Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Unified Diff: third_party/WebKit/Source/platform/network/HTTPParsers.cpp

Issue 1460883003: Drop unused functions in HTTPParsers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/network/HTTPParsers.cpp
diff --git a/third_party/WebKit/Source/platform/network/HTTPParsers.cpp b/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
index 9ac24844f245642c6783e69a0e69e2a15cc719f8..e0431662a4920abd2189f14c7ddef0917b0063b5 100644
--- a/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
+++ b/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
@@ -158,14 +158,6 @@ bool isValidHTTPToken(const String& characters)
return true;
}
-static const size_t maxInputSampleSize = 128;
-static String trimInputSample(const char* p, size_t length)
-{
- if (length > maxInputSampleSize)
- return String(p, maxInputSampleSize) + horizontalEllipsisCharacter;
- return String(p, length);
-}
-
ContentDispositionType contentDispositionType(const String& contentDisposition)
{
if (contentDisposition.isEmpty())
@@ -264,39 +256,6 @@ double parseDate(const String& value)
return parseDateFromNullTerminatedCharacters(value.utf8().data());
}
-// FIXME: This function doesn't comply with RFC 6266.
-// For example, this function doesn't handle the interaction between " and ;
-// that arises from quoted-string, nor does this function properly unquote
-// attribute values. Further this function appears to process parameter names
-// in a case-sensitive manner. (There are likely other bugs as well.)
-String filenameFromHTTPContentDisposition(const String& value)
-{
- Vector<String> keyValuePairs;
- value.split(';', keyValuePairs);
-
- unsigned length = keyValuePairs.size();
- for (unsigned i = 0; i < length; i++) {
- size_t valueStartPos = keyValuePairs[i].find('=');
- if (valueStartPos == kNotFound)
- continue;
-
- String key = keyValuePairs[i].left(valueStartPos).stripWhiteSpace();
-
- if (key.isEmpty() || key != "filename")
- continue;
-
- String value = keyValuePairs[i].substring(valueStartPos + 1).stripWhiteSpace();
-
- // Remove quotes if there are any
- if (value[0] == '\"')
- value = value.substring(1, value.length() - 2);
-
- return value;
- }
-
- return String();
-}
-
AtomicString extractMIMETypeFromMediaType(const AtomicString& mediaType)
{
StringBuilder mimeType;
@@ -479,14 +438,6 @@ ContentTypeOptionsDisposition parseContentTypeOptionsHeader(const String& header
return ContentTypeOptionsNone;
}
-String extractReasonPhraseFromHTTPStatusLine(const String& statusLine)
-{
- size_t spacePos = statusLine.find(' ');
- // Remove status code from the status line.
- spacePos = statusLine.find(' ', spacePos + 1);
- return statusLine.substring(spacePos + 1);
-}
-
XFrameOptionsDisposition parseXFrameOptionsHeader(const String& header)
{
XFrameOptionsDisposition result = XFrameOptionsNone;
@@ -517,229 +468,6 @@ XFrameOptionsDisposition parseXFrameOptionsHeader(const String& header)
return result;
}
-bool parseRange(const String& range, long long& rangeOffset, long long& rangeEnd, long long& rangeSuffixLength)
-{
- // The format of "Range" header is defined in RFC 2616 Section 14.35.1.
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1
- // We don't support multiple range requests.
-
- rangeOffset = rangeEnd = rangeSuffixLength = -1;
-
- // The "bytes" unit identifier should be present.
- static const char bytesStart[] = "bytes=";
- if (!range.startsWith(bytesStart, TextCaseInsensitive))
- return false;
- String byteRange = range.substring(sizeof(bytesStart) - 1);
-
- // The '-' character needs to be present.
- int index = byteRange.find('-');
- if (index == -1)
- return false;
-
- // If the '-' character is at the beginning, the suffix length, which specifies the last N bytes, is provided.
- // Example:
- // -500
- if (!index) {
- String suffixLengthString = byteRange.substring(index + 1).stripWhiteSpace();
- bool ok;
- long long value = suffixLengthString.toInt64Strict(&ok);
- if (ok)
- rangeSuffixLength = value;
- return true;
- }
-
- // Otherwise, the first-byte-position and the last-byte-position are provied.
- // Examples:
- // 0-499
- // 500-
- String firstBytePosStr = byteRange.left(index).stripWhiteSpace();
- bool ok;
- long long firstBytePos = firstBytePosStr.toInt64Strict(&ok);
- if (!ok)
- return false;
-
- String lastBytePosStr = byteRange.substring(index + 1).stripWhiteSpace();
- long long lastBytePos = -1;
- if (!lastBytePosStr.isEmpty()) {
- lastBytePos = lastBytePosStr.toInt64Strict(&ok);
- if (!ok)
- return false;
- }
-
- if (firstBytePos < 0 || !(lastBytePos == -1 || lastBytePos >= firstBytePos))
- return false;
-
- rangeOffset = firstBytePos;
- rangeEnd = lastBytePos;
- return true;
-}
-
-// HTTP/1.1 - RFC 2616
-// http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1
-// Request-Line = Method SP Request-URI SP HTTP-Version CRLF
-size_t parseHTTPRequestLine(const char* data, size_t length, String& failureReason, String& method, String& url, HTTPVersion& httpVersion)
-{
- method = String();
- url = String();
- httpVersion = Unknown;
-
- const char* space1 = 0;
- const char* space2 = 0;
- const char* p;
- size_t consumedLength;
-
- for (p = data, consumedLength = 0; consumedLength < length; p++, consumedLength++) {
- if (*p == ' ') {
- if (!space1)
- space1 = p;
- else if (!space2)
- space2 = p;
- } else if (*p == '\n') {
- break;
- }
- }
-
- // Haven't finished header line.
- if (consumedLength == length) {
- failureReason = "Incomplete Request Line";
- return 0;
- }
-
- // RequestLine does not contain 3 parts.
- if (!space1 || !space2) {
- failureReason = "Request Line does not appear to contain: <Method> <Url> <HTTPVersion>.";
- return 0;
- }
-
- // The line must end with "\r\n".
- const char* end = p + 1;
- if (*(end - 2) != '\r') {
- failureReason = "Request line does not end with CRLF";
- return 0;
- }
-
- // Request Method.
- method = String(data, space1 - data); // For length subtract 1 for space, but add 1 for data being the first character.
-
- // Request URI.
- url = String(space1 + 1, space2 - space1 - 1); // For length subtract 1 for space.
-
- // HTTP Version.
- String httpVersionString(space2 + 1, end - space2 - 3); // For length subtract 1 for space, and 2 for "\r\n".
- if (httpVersionString.length() != 8 || !httpVersionString.startsWith("HTTP/1."))
- httpVersion = Unknown;
- else if (httpVersionString[7] == '0')
- httpVersion = HTTP_1_0;
- else if (httpVersionString[7] == '1')
- httpVersion = HTTP_1_1;
- else
- httpVersion = Unknown;
-
- return end - data;
-}
-
-static bool parseHTTPHeaderName(const char* s, size_t start, size_t size, String& failureReason, size_t* position, AtomicString* name)
-{
- size_t nameBegin = start;
- for (size_t i = start; i < size; ++i) {
- switch (s[i]) {
- case '\r':
- failureReason = "Unexpected CR in name at " + trimInputSample(&s[nameBegin], i - nameBegin);
- return false;
- case '\n':
- failureReason = "Unexpected LF in name at " + trimInputSample(&s[nameBegin], i - nameBegin);
- return false;
- case ':':
- if (i == nameBegin) {
- failureReason = "Header name is missing";
- return false;
- }
- *name = AtomicString::fromUTF8(&s[nameBegin], i - nameBegin);
- if (name->isNull()) {
- failureReason = "Invalid UTF-8 sequence in header name";
- return false;
- }
- *position = i;
- return true;
- default:
- break;
- }
- }
- failureReason = "Unterminated header name";
- return false;
-}
-
-static bool parseHTTPHeaderValue(const char* s, size_t start, size_t size, String& failureReason, size_t* position, AtomicString* value)
-{
- size_t i = start;
- for (; i < size && s[i] == ' '; ++i) {
- }
- size_t valueBegin = i;
-
- for (; i < size && s[i] != '\r'; ++i) {
- if (s[i] == '\n') {
- failureReason = "Unexpected LF in value at " + trimInputSample(&s[valueBegin], i - valueBegin);
- return false;
- }
- }
- if (i == size) {
- failureReason = "Unterminated header value";
- return false;
- }
-
- ASSERT(i < size && s[i] == '\r');
- if (i + 1 >= size || s[i + 1] != '\n') {
- failureReason = "LF doesn't follow CR after value at " + trimInputSample(&s[i + 1], size - i - 1);
- return false;
- }
-
- *value = AtomicString::fromUTF8(&s[valueBegin], i - valueBegin);
- if (i != valueBegin && value->isNull()) {
- failureReason = "Invalid UTF-8 sequence in header value";
- return false;
- }
-
- // 2 for strlen("\r\n")
- *position = i + 2;
- return true;
-}
-
-// Note that the header is already parsed and re-formatted in chromium side.
-// We assume that the input is more restricted than RFC2616.
-size_t parseHTTPHeader(const char* s, size_t size, String& failureReason, AtomicString& name, AtomicString& value)
-{
- name = nullAtom;
- value = nullAtom;
- if (size >= 1 && s[0] == '\r') {
- if (size >= 2 && s[1] == '\n') {
- // Skip an empty line.
- return 2;
- }
- failureReason = "LF doesn't follow CR at " + trimInputSample(0, size);
- return 0;
- }
- size_t current = 0;
- if (!parseHTTPHeaderName(s, current, size, failureReason, &current, &name)) {
- return 0;
- }
- ASSERT(s[current] == ':');
- ++current;
-
- if (!parseHTTPHeaderValue(s, current, size, failureReason, &current, &value)) {
- return 0;
- }
-
- return current;
-}
-
-size_t parseHTTPRequestBody(const char* data, size_t length, Vector<unsigned char>& body)
-{
- body.clear();
- body.append(data, length);
-
- return length;
-}
-
static bool isCacheHeaderSeparator(UChar c)
{
// See RFC 2616, Section 2.2

Powered by Google App Engine
This is Rietveld 408576698