summaryrefslogtreecommitdiffstats
path: root/net/http/http_util.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-13 00:45:27 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-13 00:45:27 +0000
commit231d5a36e476d013a91ca742bb8a0a2973cfee54 (patch)
treedc5c60f8fc054503f4971b770196ed89fbfc18c1 /net/http/http_util.cc
parentf4f2df8024d7adf583a61b742a32eaa17522f154 (diff)
downloadchromium_src-231d5a36e476d013a91ca742bb8a0a2973cfee54.zip
chromium_src-231d5a36e476d013a91ca742bb8a0a2973cfee54.tar.gz
chromium_src-231d5a36e476d013a91ca742bb8a0a2973cfee54.tar.bz2
misc. http response status-line changes:
1. check for http 0.9 responses (no status line) 2. allow up to 4 bytes of junk to precede the http version. 3. distinguish between the parsed vs normalized http version (a TODO needed this). Review URL: http://codereview.chromium.org/1934 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_util.cc')
-rw-r--r--net/http/http_util.cc28
1 files changed, 26 insertions, 2 deletions
diff --git a/net/http/http_util.cc b/net/http/http_util.cc
index 0cf8c23..e67ea32 100644
--- a/net/http/http_util.cc
+++ b/net/http/http_util.cc
@@ -234,10 +234,28 @@ void HttpUtil::TrimLWS(string::const_iterator* begin,
--(*end);
}
-int HttpUtil::LocateEndOfHeaders(const char* buf, int buf_len) {
+// Find the "http" substring in a status line. This allows for
+// some slop at the start. If the "http" string could not be found
+// then returns -1.
+// static
+int HttpUtil::LocateStartOfStatusLine(const char* buf, int buf_len) {
+ const int slop = 4;
+ const int http_len = 4;
+
+ if (buf_len >= http_len) {
+ int i_max = std::min(buf_len - http_len, slop);
+ for (int i = 0; i <= i_max; ++i) {
+ if (LowerCaseEqualsASCII(buf + i, buf + i + http_len, "http"))
+ return i;
+ }
+ }
+ return -1; // Not found
+}
+
+int HttpUtil::LocateEndOfHeaders(const char* buf, int buf_len, int i) {
bool was_lf = false;
char last_c = '\0';
- for (int i = 0; i < buf_len; ++i) {
+ for (; i < buf_len; ++i) {
char c = buf[i];
if (c == '\n') {
if (was_lf)
@@ -300,6 +318,12 @@ std::string HttpUtil::AssembleRawHeaders(const char* input_begin,
const char* input_end = input_begin + input_len;
+ // Skip any leading slop, since the consumers of this output
+ // (HttpResponseHeaders) don't deal with it.
+ int status_begin_offset = LocateStartOfStatusLine(input_begin, input_len);
+ if (status_begin_offset != -1)
+ input_begin += status_begin_offset;
+
// Copy the status line.
const char* status_line_end = FindStatusLineEnd(input_begin, input_end);
raw_headers.append(input_begin, status_line_end);