diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-20 04:06:48 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-20 04:06:48 +0000 |
commit | 099cec761ad00232f5ce8483a163356b06065980 (patch) | |
tree | c49c284e22db6e8ca8edf7a702c8469f4fbc36a3 /net | |
parent | fb86b681a52cff45f5dd1137f493d8bf4c1461f2 (diff) | |
download | chromium_src-099cec761ad00232f5ce8483a163356b06065980.zip chromium_src-099cec761ad00232f5ce8483a163356b06065980.tar.gz chromium_src-099cec761ad00232f5ce8483a163356b06065980.tar.bz2 |
Portability changes to http_response_headers.
The parsing changes will also behave differently for these cases (added as unit-tests):
"Content-Length: +10\n"
Before: 10
After: -1
"Content-Length: 40000000000000000000\n"
Before: 9223372036854775807
After: -1
"Content-Length: \v10\n"
Before: 10
After: -1
"Content-Length: \f10\n"
Before: 10
After: -1
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1083 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_response_headers.cc | 17 | ||||
-rw-r--r-- | net/http/http_response_headers_unittest.cc | 41 |
2 files changed, 48 insertions, 10 deletions
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index 38e2fe2..7ec62a3 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -35,7 +35,6 @@ #include "net/http/http_response_headers.h" #include <algorithm> -#include <hash_map> #include "base/logging.h" #include "base/pickle.h" @@ -265,7 +264,7 @@ void HttpResponseHeaders::GetNormalizedHeaders(string* output) const { // be a web app, we cannot be certain of the semantics of commas despite the // fact that RFC 2616 says that they should be regarded as value separators. // - typedef stdext::hash_map<string, size_t> HeadersMap; + typedef base::hash_map<string, size_t> HeadersMap; HeadersMap headers_map; HeadersMap::iterator iter = headers_map.end(); @@ -909,6 +908,8 @@ bool HttpResponseHeaders::IsKeepAlive() const { return keep_alive; } +// From RFC 2616: +// Content-Length = "Content-Length" ":" 1*DIGIT int64 HttpResponseHeaders::GetContentLength() const { void* iter = NULL; string content_length_val; @@ -918,16 +919,12 @@ int64 HttpResponseHeaders::GetContentLength() const { if (content_length_val.empty()) return -1; - // NOTE: We do not use StringToInt64 here since we want to know if - // parsing failed. - - char* end; - int64 result = _strtoi64(content_length_val.c_str(), &end, 10); - - if (result < 0) + if (content_length_val[0] == '+') return -1; - if (end != content_length_val.c_str() + content_length_val.length()) + int64 result; + bool ok = StringToInt64(content_length_val, &result); + if (!ok || result < 0) return -1; return result; diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc index 41b7c563..45bcaaa 100644 --- a/net/http/http_response_headers_unittest.cc +++ b/net/http/http_response_headers_unittest.cc @@ -896,6 +896,10 @@ TEST(HttpResponseHeadersTest, GetContentLength) { -1 }, { "HTTP/1.1 200 OK\n" + "Content-Length: +10\n", + -1 + }, + { "HTTP/1.1 200 OK\n" "Content-Length: 23xb5\n", -1 }, @@ -903,6 +907,43 @@ TEST(HttpResponseHeadersTest, GetContentLength) { "Content-Length: 0xA\n", -1 }, + { "HTTP/1.1 200 OK\n" + "Content-Length: 010\n", + 10 + }, + // Content-Length too big, will overflow an int64 + { "HTTP/1.1 200 OK\n" + "Content-Length: 40000000000000000000\n", + -1 + }, + { "HTTP/1.1 200 OK\n" + "Content-Length: 10\n", + 10 + }, + { "HTTP/1.1 200 OK\n" + "Content-Length: 10 \n", + 10 + }, + { "HTTP/1.1 200 OK\n" + "Content-Length: \t10\n", + 10 + }, + { "HTTP/1.1 200 OK\n" + "Content-Length: \v10\n", + -1 + }, + { "HTTP/1.1 200 OK\n" + "Content-Length: \f10\n", + -1 + }, + { "HTTP/1.1 200 OK\n" + "cOnTeNt-LENgth: 33\n", + 33 + }, + { "HTTP/1.1 200 OK\n" + "Content-Length: 34\r\n", + -1 + }, }; for (size_t i = 0; i < arraysize(tests); ++i) { string headers(tests[i].headers); |