This source file includes following definitions.
- parseHTTPRequestFromBuffer
- parseRequestLine
- parseHeaders
- parseRequestBody
- m_requestMethod
#include "config.h"
#include "platform/network/HTTPRequest.h"
#include "wtf/text/CString.h"
namespace WebCore {
PassRefPtr<HTTPRequest> HTTPRequest::parseHTTPRequestFromBuffer(const char* data, size_t length, String& failureReason)
{
if (!length) {
failureReason = "No data to parse.";
return nullptr;
}
RefPtr<HTTPRequest> request = HTTPRequest::create();
const char* pos = data;
size_t remainingLength = length;
size_t requestLineLength = request->parseRequestLine(pos, remainingLength, failureReason);
if (!requestLineLength)
return nullptr;
pos += requestLineLength;
remainingLength -= requestLineLength;
size_t headersLength = request->parseHeaders(pos, remainingLength, failureReason);
if (!headersLength)
return nullptr;
pos += headersLength;
remainingLength -= headersLength;
size_t dataLength = request->parseRequestBody(pos, remainingLength);
remainingLength -= dataLength;
ASSERT(!remainingLength);
return request.release();
}
size_t HTTPRequest::parseRequestLine(const char* data, size_t length, String& failureReason)
{
String url;
size_t result = parseHTTPRequestLine(data, length, failureReason, m_requestMethod, url, m_httpVersion);
m_url = KURL(KURL(), url);
return result;
}
size_t HTTPRequest::parseHeaders(const char* data, size_t length, String& failureReason)
{
const char* p = data;
const char* end = data + length;
AtomicString name;
AtomicString value;
for (; p < data + length; p++) {
size_t consumedLength = parseHTTPHeader(p, end - p, failureReason, name, value);
if (!consumedLength)
return 0;
p += consumedLength;
if (name.isEmpty())
break;
m_headerFields.add(name, value);
}
return p - data;
}
size_t HTTPRequest::parseRequestBody(const char* data, size_t length)
{
return parseHTTPRequestBody(data, length, m_body);
}
HTTPRequest::HTTPRequest()
: m_httpVersion(Unknown)
{
}
HTTPRequest::HTTPRequest(const String& requestMethod, const KURL& url, HTTPVersion version)
: m_url(url)
, m_httpVersion(version)
, m_requestMethod(requestMethod)
{
}
HTTPRequest::~HTTPRequest()
{
}
}