Index: net/http/http_util_unittest.cc |
diff --git a/net/http/http_util_unittest.cc b/net/http/http_util_unittest.cc |
index 54acf68d3c3d52c3bc28aa4b0f9ee3603ac098cd..3240cf3865890803d347a4176592cc34c8c827f6 100644 |
--- a/net/http/http_util_unittest.cc |
+++ b/net/http/http_util_unittest.cc |
@@ -17,86 +17,55 @@ class HttpUtilTest : public testing::Test {}; |
TEST(HttpUtilTest, IsSafeHeader) { |
static const char* unsafe_headers[] = { |
- "sec-", |
- "sEc-", |
- "sec-foo", |
- "sEc-FoO", |
- "proxy-", |
- "pRoXy-", |
- "proxy-foo", |
- "pRoXy-FoO", |
- "accept-charset", |
- "accept-encoding", |
- "access-control-request-headers", |
- "access-control-request-method", |
- "connection", |
- "content-length", |
- "cookie", |
- "cookie2", |
- "content-transfer-encoding", |
- "date", |
- "expect", |
- "host", |
- "keep-alive", |
- "origin", |
- "referer", |
- "te", |
- "trailer", |
- "transfer-encoding", |
- "upgrade", |
- "user-agent", |
- "via", |
+ "sec-", "sEc-", |
+ "sec-foo", "sEc-FoO", |
+ "proxy-", "pRoXy-", |
+ "proxy-foo", "pRoXy-FoO", |
+ "accept-charset", "accept-encoding", |
+ "access-control-request-headers", "access-control-request-method", |
+ "connection", "content-length", |
+ "cookie", "cookie2", |
+ "content-transfer-encoding", "date", |
+ "expect", "host", |
+ "keep-alive", "origin", |
+ "referer", "te", |
+ "trailer", "transfer-encoding", |
+ "upgrade", "user-agent", |
+ "via", |
}; |
for (size_t i = 0; i < arraysize(unsafe_headers); ++i) { |
EXPECT_FALSE(HttpUtil::IsSafeHeader(unsafe_headers[i])) |
- << unsafe_headers[i]; |
- EXPECT_FALSE(HttpUtil::IsSafeHeader(StringToUpperASCII(std::string( |
- unsafe_headers[i])))) << unsafe_headers[i]; |
+ << unsafe_headers[i]; |
+ EXPECT_FALSE(HttpUtil::IsSafeHeader( |
+ StringToUpperASCII(std::string(unsafe_headers[i])))) |
+ << unsafe_headers[i]; |
} |
static const char* safe_headers[] = { |
- "foo", |
- "x-", |
- "x-foo", |
- "content-disposition", |
- "update", |
- "accept-charseta", |
- "accept_charset", |
- "accept-encodinga", |
- "accept_encoding", |
- "access-control-request-headersa", |
- "access-control-request-header", |
- "access_control_request_header", |
- "access-control-request-methoda", |
- "access_control_request_method", |
- "connectiona", |
- "content-lengtha", |
- "content_length", |
- "cookiea", |
- "cookie2a", |
- "cookie3", |
- "content-transfer-encodinga", |
- "content_transfer_encoding", |
- "datea", |
- "expecta", |
- "hosta", |
- "keep-alivea", |
- "keep_alive", |
- "origina", |
- "referera", |
- "referrer", |
- "tea", |
- "trailera", |
- "transfer-encodinga", |
- "transfer_encoding", |
- "upgradea", |
- "user-agenta", |
- "user_agent", |
- "viaa", |
+ "foo", "x-", |
+ "x-foo", "content-disposition", |
+ "update", "accept-charseta", |
+ "accept_charset", "accept-encodinga", |
+ "accept_encoding", "access-control-request-headersa", |
+ "access-control-request-header", "access_control_request_header", |
+ "access-control-request-methoda", "access_control_request_method", |
+ "connectiona", "content-lengtha", |
+ "content_length", "cookiea", |
+ "cookie2a", "cookie3", |
+ "content-transfer-encodinga", "content_transfer_encoding", |
+ "datea", "expecta", |
+ "hosta", "keep-alivea", |
+ "keep_alive", "origina", |
+ "referera", "referrer", |
+ "tea", "trailera", |
+ "transfer-encodinga", "transfer_encoding", |
+ "upgradea", "user-agenta", |
+ "user_agent", "viaa", |
}; |
for (size_t i = 0; i < arraysize(safe_headers); ++i) { |
EXPECT_TRUE(HttpUtil::IsSafeHeader(safe_headers[i])) << safe_headers[i]; |
- EXPECT_TRUE(HttpUtil::IsSafeHeader(StringToUpperASCII(std::string( |
- safe_headers[i])))) << safe_headers[i]; |
+ EXPECT_TRUE(HttpUtil::IsSafeHeader( |
+ StringToUpperASCII(std::string(safe_headers[i])))) |
+ << safe_headers[i]; |
} |
} |
@@ -106,14 +75,14 @@ TEST(HttpUtilTest, HasHeader) { |
const char* name; |
bool expected_result; |
} tests[] = { |
- { "", "foo", false }, |
- { "foo\r\nbar", "foo", false }, |
- { "ffoo: 1", "foo", false }, |
- { "foo: 1", "foo", true }, |
- { "foo: 1\r\nbar: 2", "foo", true }, |
- { "fOO: 1\r\nbar: 2", "foo", true }, |
- { "g: 0\r\nfoo: 1\r\nbar: 2", "foo", true }, |
- }; |
+ {"", "foo", false}, |
+ {"foo\r\nbar", "foo", false}, |
+ {"ffoo: 1", "foo", false}, |
+ {"foo: 1", "foo", true}, |
+ {"foo: 1\r\nbar: 2", "foo", true}, |
+ {"fOO: 1\r\nbar: 2", "foo", true}, |
+ {"g: 0\r\nfoo: 1\r\nbar: 2", "foo", true}, |
+ }; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
bool result = HttpUtil::HasHeader(tests[i].headers, tests[i].name); |
EXPECT_EQ(tests[i].expected_result, result); |
@@ -130,17 +99,15 @@ TEST(HttpUtilTest, StripHeaders) { |
"Server: Apache\r\n" |
"OrIGin: origin2\r\n"; |
- static const char* header_names[] = { |
- "origin", "content-type", "cookies" |
- }; |
+ static const char* header_names[] = {"origin", "content-type", "cookies"}; |
static const char* expected_stripped_headers = |
"Custom: baz\r\n" |
"Server: Apache\r\n"; |
- EXPECT_EQ(expected_stripped_headers, |
- HttpUtil::StripHeaders(headers, header_names, |
- arraysize(header_names))); |
+ EXPECT_EQ( |
+ expected_stripped_headers, |
+ HttpUtil::StripHeaders(headers, header_names, arraysize(header_names))); |
} |
TEST(HttpUtilTest, HeadersIterator) { |
@@ -265,13 +232,13 @@ TEST(HttpUtilTest, LocateEndOfHeaders) { |
const char* input; |
int expected_result; |
} tests[] = { |
- { "foo\r\nbar\r\n\r\n", 12 }, |
- { "foo\nbar\n\n", 9 }, |
- { "foo\r\nbar\r\n\r\njunk", 12 }, |
- { "foo\nbar\n\njunk", 9 }, |
- { "foo\nbar\n\r\njunk", 10 }, |
- { "foo\nbar\r\n\njunk", 10 }, |
- }; |
+ {"foo\r\nbar\r\n\r\n", 12}, |
+ {"foo\nbar\n\n", 9}, |
+ {"foo\r\nbar\r\n\r\njunk", 12}, |
+ {"foo\nbar\n\njunk", 9}, |
+ {"foo\nbar\n\r\njunk", 10}, |
+ {"foo\nbar\r\n\njunk", 10}, |
+ }; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
int input_len = static_cast<int>(strlen(tests[i].input)); |
int eoh = HttpUtil::LocateEndOfHeaders(tests[i].input, input_len); |
@@ -281,307 +248,243 @@ TEST(HttpUtilTest, LocateEndOfHeaders) { |
TEST(HttpUtilTest, AssembleRawHeaders) { |
struct { |
- const char* input; // with '|' representing '\0' |
+ const char* input; // with '|' representing '\0' |
const char* expected_result; // with '\0' changed to '|' |
} tests[] = { |
- { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", |
- "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, |
- |
- { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", |
- "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, |
- |
- // Valid line continuation (single SP). |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- " continuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1 continuation|" |
- "Bar: 2||" |
- }, |
- |
- // Valid line continuation (single HT). |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- "\tcontinuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1 continuation|" |
- "Bar: 2||" |
- }, |
- |
- // Valid line continuation (multiple SP). |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- " continuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1 continuation|" |
- "Bar: 2||" |
- }, |
- |
- // Valid line continuation (multiple HT). |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- "\t\t\tcontinuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1 continuation|" |
- "Bar: 2||" |
- }, |
- |
- // Valid line continuation (mixed HT, SP). |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- " \t \t continuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1 continuation|" |
- "Bar: 2||" |
- }, |
- |
- // Valid multi-line continuation |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- " continuation1\n" |
- "\tcontinuation2\n" |
- " continuation3\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1 continuation1 continuation2 continuation3|" |
- "Bar: 2||" |
- }, |
- |
- // Continuation of quoted value. |
- // This is different from what Firefox does, since it |
- // will preserve the LWS. |
- { |
- "HTTP/1.0 200 OK\n" |
- "Etag: \"34534-d3\n" |
- " 134q\"\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Etag: \"34534-d3 134q\"|" |
- "Bar: 2||" |
- }, |
- |
- // Valid multi-line continuation, full LWS lines |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- " \n" |
- "\t\t\t\t\n" |
- "\t continuation\n" |
- "Bar: 2\n\n", |
- |
- // One SP per continued line = 3. |
- "HTTP/1.0 200 OK|" |
- "Foo: 1 continuation|" |
- "Bar: 2||" |
- }, |
- |
- // Valid multi-line continuation, all LWS |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- " \n" |
- "\t\t\t\t\n" |
- "\t \n" |
- "Bar: 2\n\n", |
- |
- // One SP per continued line = 3. |
- "HTTP/1.0 200 OK|" |
- "Foo: 1 |" |
- "Bar: 2||" |
- }, |
- |
- // Valid line continuation (No value bytes in first line). |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo:\n" |
- " value\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: value|" |
- "Bar: 2||" |
- }, |
- |
- // Not a line continuation (can't continue status line). |
- { |
- "HTTP/1.0 200 OK\n" |
- " Foo: 1\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- " Foo: 1|" |
- "Bar: 2||" |
- }, |
- |
- // Not a line continuation (can't continue status line). |
- { |
- "HTTP/1.0\n" |
- " 200 OK\n" |
- "Foo: 1\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0|" |
- " 200 OK|" |
- "Foo: 1|" |
- "Bar: 2||" |
- }, |
- |
- // Not a line continuation (can't continue status line). |
- { |
- "HTTP/1.0 404\n" |
- " Not Found\n" |
- "Foo: 1\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 404|" |
- " Not Found|" |
- "Foo: 1|" |
- "Bar: 2||" |
- }, |
- |
- // Unterminated status line. |
- { |
- "HTTP/1.0 200 OK", |
- |
- "HTTP/1.0 200 OK||" |
- }, |
- |
- // Single terminated, with headers |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- "Bar: 2\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1|" |
- "Bar: 2||" |
- }, |
- |
- // Not terminated, with headers |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- "Bar: 2", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1|" |
- "Bar: 2||" |
- }, |
- |
- // Not a line continuation (VT) |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- "\vInvalidContinuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1|" |
- "\vInvalidContinuation|" |
- "Bar: 2||" |
- }, |
- |
- // Not a line continuation (formfeed) |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- "\fInvalidContinuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1|" |
- "\fInvalidContinuation|" |
- "Bar: 2||" |
- }, |
- |
- // Not a line continuation -- can't continue header names. |
- { |
- "HTTP/1.0 200 OK\n" |
- "Serv\n" |
- " er: Apache\n" |
- "\tInvalidContinuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Serv|" |
- " er: Apache|" |
- "\tInvalidContinuation|" |
- "Bar: 2||" |
- }, |
- |
- // Not a line continuation -- no value to continue. |
- { |
- "HTTP/1.0 200 OK\n" |
- "Foo: 1\n" |
- "garbage\n" |
- " not-a-continuation\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- "Foo: 1|" |
- "garbage|" |
- " not-a-continuation|" |
- "Bar: 2||", |
- }, |
- |
- // Not a line continuation -- no valid name. |
- { |
- "HTTP/1.0 200 OK\n" |
- ": 1\n" |
- " garbage\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- ": 1|" |
- " garbage|" |
- "Bar: 2||", |
- }, |
- |
- // Not a line continuation -- no valid name (whitespace) |
- { |
- "HTTP/1.0 200 OK\n" |
- " : 1\n" |
- " garbage\n" |
- "Bar: 2\n\n", |
- |
- "HTTP/1.0 200 OK|" |
- " : 1|" |
- " garbage|" |
- "Bar: 2||", |
- }, |
- |
- // Embed NULLs in the status line. They should not be understood |
- // as line separators. |
- { |
- "HTTP/1.0 200 OK|Bar2:0|Baz2:1\r\nFoo: 1\r\nBar: 2\r\n\r\n", |
- "HTTP/1.0 200 OKBar2:0Baz2:1|Foo: 1|Bar: 2||" |
- }, |
- |
- // Embed NULLs in a header line. They should not be understood as |
- // line separators. |
- { |
- "HTTP/1.0 200 OK\nFoo: 1|Foo2: 3\nBar: 2\n\n", |
- "HTTP/1.0 200 OK|Foo: 1Foo2: 3|Bar: 2||" |
- }, |
- }; |
+ {"HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", |
+ "HTTP/1.0 200 OK|Foo: 1|Bar: 2||"}, |
+ {"HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", |
+ "HTTP/1.0 200 OK|Foo: 1|Bar: 2||"}, |
+ |
+ // Valid line continuation (single SP). |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ " continuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1 continuation|" |
+ "Bar: 2||"}, |
+ |
+ // Valid line continuation (single HT). |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ "\tcontinuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1 continuation|" |
+ "Bar: 2||"}, |
+ |
+ // Valid line continuation (multiple SP). |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ " continuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1 continuation|" |
+ "Bar: 2||"}, |
+ |
+ // Valid line continuation (multiple HT). |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ "\t\t\tcontinuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1 continuation|" |
+ "Bar: 2||"}, |
+ |
+ // Valid line continuation (mixed HT, SP). |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ " \t \t continuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1 continuation|" |
+ "Bar: 2||"}, |
+ |
+ // Valid multi-line continuation |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ " continuation1\n" |
+ "\tcontinuation2\n" |
+ " continuation3\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1 continuation1 continuation2 continuation3|" |
+ "Bar: 2||"}, |
+ |
+ // Continuation of quoted value. |
+ // This is different from what Firefox does, since it |
+ // will preserve the LWS. |
+ {"HTTP/1.0 200 OK\n" |
+ "Etag: \"34534-d3\n" |
+ " 134q\"\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Etag: \"34534-d3 134q\"|" |
+ "Bar: 2||"}, |
+ |
+ // Valid multi-line continuation, full LWS lines |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ " \n" |
+ "\t\t\t\t\n" |
+ "\t continuation\n" |
+ "Bar: 2\n\n", |
+ |
+ // One SP per continued line = 3. |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1 continuation|" |
+ "Bar: 2||"}, |
+ |
+ // Valid multi-line continuation, all LWS |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ " \n" |
+ "\t\t\t\t\n" |
+ "\t \n" |
+ "Bar: 2\n\n", |
+ |
+ // One SP per continued line = 3. |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1 |" |
+ "Bar: 2||"}, |
+ |
+ // Valid line continuation (No value bytes in first line). |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo:\n" |
+ " value\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: value|" |
+ "Bar: 2||"}, |
+ |
+ // Not a line continuation (can't continue status line). |
+ {"HTTP/1.0 200 OK\n" |
+ " Foo: 1\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ " Foo: 1|" |
+ "Bar: 2||"}, |
+ |
+ // Not a line continuation (can't continue status line). |
+ {"HTTP/1.0\n" |
+ " 200 OK\n" |
+ "Foo: 1\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0|" |
+ " 200 OK|" |
+ "Foo: 1|" |
+ "Bar: 2||"}, |
+ |
+ // Not a line continuation (can't continue status line). |
+ {"HTTP/1.0 404\n" |
+ " Not Found\n" |
+ "Foo: 1\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 404|" |
+ " Not Found|" |
+ "Foo: 1|" |
+ "Bar: 2||"}, |
+ |
+ // Unterminated status line. |
+ {"HTTP/1.0 200 OK", "HTTP/1.0 200 OK||"}, |
+ |
+ // Single terminated, with headers |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ "Bar: 2\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1|" |
+ "Bar: 2||"}, |
+ |
+ // Not terminated, with headers |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ "Bar: 2", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1|" |
+ "Bar: 2||"}, |
+ |
+ // Not a line continuation (VT) |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ "\vInvalidContinuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1|" |
+ "\vInvalidContinuation|" |
+ "Bar: 2||"}, |
+ |
+ // Not a line continuation (formfeed) |
+ {"HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ "\fInvalidContinuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1|" |
+ "\fInvalidContinuation|" |
+ "Bar: 2||"}, |
+ |
+ // Not a line continuation -- can't continue header names. |
+ {"HTTP/1.0 200 OK\n" |
+ "Serv\n" |
+ " er: Apache\n" |
+ "\tInvalidContinuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Serv|" |
+ " er: Apache|" |
+ "\tInvalidContinuation|" |
+ "Bar: 2||"}, |
+ |
+ // Not a line continuation -- no value to continue. |
+ { |
+ "HTTP/1.0 200 OK\n" |
+ "Foo: 1\n" |
+ "garbage\n" |
+ " not-a-continuation\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ "Foo: 1|" |
+ "garbage|" |
+ " not-a-continuation|" |
+ "Bar: 2||", |
+ }, |
+ |
+ // Not a line continuation -- no valid name. |
+ { |
+ "HTTP/1.0 200 OK\n" |
+ ": 1\n" |
+ " garbage\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ ": 1|" |
+ " garbage|" |
+ "Bar: 2||", |
+ }, |
+ |
+ // Not a line continuation -- no valid name (whitespace) |
+ { |
+ "HTTP/1.0 200 OK\n" |
+ " : 1\n" |
+ " garbage\n" |
+ "Bar: 2\n\n", |
+ "HTTP/1.0 200 OK|" |
+ " : 1|" |
+ " garbage|" |
+ "Bar: 2||", |
+ }, |
+ |
+ // Embed NULLs in the status line. They should not be understood |
+ // as line separators. |
+ {"HTTP/1.0 200 OK|Bar2:0|Baz2:1\r\nFoo: 1\r\nBar: 2\r\n\r\n", |
+ "HTTP/1.0 200 OKBar2:0Baz2:1|Foo: 1|Bar: 2||"}, |
+ |
+ // Embed NULLs in a header line. They should not be understood as |
+ // line separators. |
+ {"HTTP/1.0 200 OK\nFoo: 1|Foo2: 3\nBar: 2\n\n", |
+ "HTTP/1.0 200 OK|Foo: 1Foo2: 3|Bar: 2||"}, |
+ }; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
std::string input = tests[i].input; |
std::replace(input.begin(), input.end(), '|', '\0'); |
@@ -597,38 +500,23 @@ TEST(HttpUtilTest, RequestUrlSanitize) { |
const char* url; |
const char* expected_spec; |
const char* expected_path; |
- } tests[] = { |
- { // Check that #hash is removed. |
- "http://www.google.com:78/foobar?query=1#hash", |
- "http://www.google.com:78/foobar?query=1", |
- "/foobar?query=1" |
- }, |
- { // The reference may itself contain # -- strip all of it. |
- "http://192.168.0.1?query=1#hash#10#11#13#14", |
- "http://192.168.0.1/?query=1", |
- "/?query=1" |
- }, |
- { // Strip username/password. |
- "http://user:pass@google.com", |
- "http://google.com/", |
- "/" |
- }, |
- { // https scheme |
- "https://www.google.com:78/foobar?query=1#hash", |
- "https://www.google.com:78/foobar?query=1", |
- "/foobar?query=1" |
- }, |
- { // WebSocket's ws scheme |
- "ws://www.google.com:78/foobar?query=1#hash", |
- "ws://www.google.com:78/foobar?query=1", |
- "/foobar?query=1" |
- }, |
- { // WebSocket's wss scheme |
- "wss://www.google.com:78/foobar?query=1#hash", |
- "wss://www.google.com:78/foobar?query=1", |
- "/foobar?query=1" |
- } |
- }; |
+ } tests[] = {{// Check that #hash is removed. |
+ "http://www.google.com:78/foobar?query=1#hash", |
+ "http://www.google.com:78/foobar?query=1", "/foobar?query=1"}, |
+ {// The reference may itself contain # -- strip all of it. |
+ "http://192.168.0.1?query=1#hash#10#11#13#14", |
+ "http://192.168.0.1/?query=1", "/?query=1"}, |
+ {// Strip username/password. |
+ "http://user:pass@google.com", "http://google.com/", "/"}, |
+ {// https scheme |
+ "https://www.google.com:78/foobar?query=1#hash", |
+ "https://www.google.com:78/foobar?query=1", "/foobar?query=1"}, |
+ {// WebSocket's ws scheme |
+ "ws://www.google.com:78/foobar?query=1#hash", |
+ "ws://www.google.com:78/foobar?query=1", "/foobar?query=1"}, |
+ {// WebSocket's wss scheme |
+ "wss://www.google.com:78/foobar?query=1#hash", |
+ "wss://www.google.com:78/foobar?query=1", "/foobar?query=1"}}; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
GURL url(GURL(tests[i].url)); |
std::string expected_spec(tests[i].expected_spec); |
@@ -649,8 +537,9 @@ TEST(HttpUtilTest, SpecForRequestForUrlWithFtpScheme) { |
TEST(HttpUtilTest, GenerateAcceptLanguageHeader) { |
EXPECT_EQ(std::string("en-US,fr;q=0.8,de;q=0.6"), |
HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de")); |
- EXPECT_EQ(std::string("en-US,fr;q=0.8,de;q=0.6,ko;q=0.4,zh-CN;q=0.2," |
- "ja;q=0.2"), |
+ EXPECT_EQ(std::string( |
+ "en-US,fr;q=0.8,de;q=0.6,ko;q=0.4,zh-CN;q=0.2," |
+ "ja;q=0.2"), |
HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja")); |
} |
@@ -663,75 +552,31 @@ TEST(HttpUtilTest, ParseContentType) { |
const bool expected_had_charset; |
const char* expected_boundary; |
} tests[] = { |
- { "text/html; charset=utf-8", |
- "text/html", |
- "utf-8", |
- true, |
- "" |
- }, |
- { "text/html; charset =utf-8", |
- "text/html", |
- "utf-8", |
- true, |
- "" |
- }, |
- { "text/html; charset= utf-8", |
- "text/html", |
- "utf-8", |
- true, |
- "" |
- }, |
- { "text/html; charset=utf-8 ", |
- "text/html", |
- "utf-8", |
- true, |
- "" |
- }, |
- { "text/html; boundary=\"WebKit-ada-df-dsf-adsfadsfs\"", |
- "text/html", |
- "", |
- false, |
- "\"WebKit-ada-df-dsf-adsfadsfs\"" |
- }, |
- { "text/html; boundary =\"WebKit-ada-df-dsf-adsfadsfs\"", |
- "text/html", |
- "", |
- false, |
- "\"WebKit-ada-df-dsf-adsfadsfs\"" |
- }, |
- { "text/html; boundary= \"WebKit-ada-df-dsf-adsfadsfs\"", |
- "text/html", |
- "", |
- false, |
- "\"WebKit-ada-df-dsf-adsfadsfs\"" |
- }, |
- { "text/html; boundary= \"WebKit-ada-df-dsf-adsfadsfs\" ", |
- "text/html", |
- "", |
- false, |
- "\"WebKit-ada-df-dsf-adsfadsfs\"" |
- }, |
- { "text/html; boundary=\"WebKit-ada-df-dsf-adsfadsfs \"", |
- "text/html", |
- "", |
- false, |
- "\"WebKit-ada-df-dsf-adsfadsfs \"" |
- }, |
- { "text/html; boundary=WebKit-ada-df-dsf-adsfadsfs", |
- "text/html", |
- "", |
- false, |
- "WebKit-ada-df-dsf-adsfadsfs" |
- }, |
- // TODO(abarth): Add more interesting test cases. |
- }; |
+ {"text/html; charset=utf-8", "text/html", "utf-8", true, ""}, |
+ {"text/html; charset =utf-8", "text/html", "utf-8", true, ""}, |
+ {"text/html; charset= utf-8", "text/html", "utf-8", true, ""}, |
+ {"text/html; charset=utf-8 ", "text/html", "utf-8", true, ""}, |
+ {"text/html; boundary=\"WebKit-ada-df-dsf-adsfadsfs\"", "text/html", "", |
+ false, "\"WebKit-ada-df-dsf-adsfadsfs\""}, |
+ {"text/html; boundary =\"WebKit-ada-df-dsf-adsfadsfs\"", "text/html", |
+ "", false, "\"WebKit-ada-df-dsf-adsfadsfs\""}, |
+ {"text/html; boundary= \"WebKit-ada-df-dsf-adsfadsfs\"", "text/html", |
+ "", false, "\"WebKit-ada-df-dsf-adsfadsfs\""}, |
+ {"text/html; boundary= \"WebKit-ada-df-dsf-adsfadsfs\" ", "text/html", |
+ "", false, "\"WebKit-ada-df-dsf-adsfadsfs\""}, |
+ {"text/html; boundary=\"WebKit-ada-df-dsf-adsfadsfs \"", "text/html", |
+ "", false, "\"WebKit-ada-df-dsf-adsfadsfs \""}, |
+ {"text/html; boundary=WebKit-ada-df-dsf-adsfadsfs", "text/html", "", |
+ false, "WebKit-ada-df-dsf-adsfadsfs"}, |
+ // TODO(abarth): Add more interesting test cases. |
+ }; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
std::string mime_type; |
std::string charset; |
bool had_charset = false; |
std::string boundary; |
- net::HttpUtil::ParseContentType(tests[i].content_type, &mime_type, |
- &charset, &had_charset, &boundary); |
+ net::HttpUtil::ParseContentType( |
+ tests[i].content_type, &mime_type, &charset, &had_charset, &boundary); |
EXPECT_EQ(tests[i].expected_mime_type, mime_type) << "i=" << i; |
EXPECT_EQ(tests[i].expected_charset, charset) << "i=" << i; |
EXPECT_EQ(tests[i].expected_had_charset, had_charset) << "i=" << i; |
@@ -750,113 +595,62 @@ TEST(HttpUtilTest, ParseRanges) { |
int64 expected_suffix_length; |
} expected_ranges[10]; |
} tests[] = { |
- { "Range: bytes=0-10", |
- true, |
- 1, |
- { {0, 10, -1}, } |
- }, |
- { "Range: bytes=10-0", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: BytES=0-10", |
- true, |
- 1, |
- { {0, 10, -1}, } |
- }, |
- { "Range: megabytes=0-10", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: bytes0-10", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: bytes=0-0,0-10,10-20,100-200,100-,-200", |
- true, |
- 6, |
- { {0, 0, -1}, |
- {0, 10, -1}, |
- {10, 20, -1}, |
- {100, 200, -1}, |
- {100, -1, -1}, |
- {-1, -1, 200}, |
- } |
- }, |
- { "Range: bytes=0-10\r\n" |
- "Range: bytes=0-10,10-20,100-200,100-,-200", |
- true, |
- 1, |
- { {0, 10, -1} |
- } |
- }, |
- { "Range: bytes=", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: bytes=-", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: bytes=0-10-", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: bytes=-0-10", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: bytes =0-10\r\n", |
- true, |
- 1, |
- { {0, 10, -1} |
- } |
- }, |
- { "Range: bytes= 0-10 \r\n", |
- true, |
- 1, |
- { {0, 10, -1} |
- } |
- }, |
- { "Range: bytes = 0 - 10 \r\n", |
- true, |
- 1, |
- { {0, 10, -1} |
- } |
- }, |
- { "Range: bytes= 0-1 0\r\n", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: bytes= 0- -10\r\n", |
- false, |
- 0, |
- {} |
- }, |
- { "Range: bytes= 0 - 1 , 10 -20, 100- 200 , 100-, -200 \r\n", |
- true, |
- 5, |
- { {0, 1, -1}, |
- {10, 20, -1}, |
- {100, 200, -1}, |
- {100, -1, -1}, |
- {-1, -1, 200}, |
- } |
- }, |
- }; |
+ {"Range: bytes=0-10", |
+ true, |
+ 1, |
+ { |
+ {0, 10, -1}, |
+ }}, |
+ {"Range: bytes=10-0", false, 0, {}}, |
+ {"Range: BytES=0-10", |
+ true, |
+ 1, |
+ { |
+ {0, 10, -1}, |
+ }}, |
+ {"Range: megabytes=0-10", false, 0, {}}, |
+ {"Range: bytes0-10", false, 0, {}}, |
+ {"Range: bytes=0-0,0-10,10-20,100-200,100-,-200", |
+ true, |
+ 6, |
+ { |
+ {0, 0, -1}, |
+ {0, 10, -1}, |
+ {10, 20, -1}, |
+ {100, 200, -1}, |
+ {100, -1, -1}, |
+ {-1, -1, 200}, |
+ }}, |
+ {"Range: bytes=0-10\r\n" |
+ "Range: bytes=0-10,10-20,100-200,100-,-200", |
+ true, |
+ 1, |
+ {{0, 10, -1}}}, |
+ {"Range: bytes=", false, 0, {}}, |
+ {"Range: bytes=-", false, 0, {}}, |
+ {"Range: bytes=0-10-", false, 0, {}}, |
+ {"Range: bytes=-0-10", false, 0, {}}, |
+ {"Range: bytes =0-10\r\n", true, 1, {{0, 10, -1}}}, |
+ {"Range: bytes= 0-10 \r\n", true, 1, {{0, 10, -1}}}, |
+ {"Range: bytes = 0 - 10 \r\n", true, 1, {{0, 10, -1}}}, |
+ {"Range: bytes= 0-1 0\r\n", false, 0, {}}, |
+ {"Range: bytes= 0- -10\r\n", false, 0, {}}, |
+ {"Range: bytes= 0 - 1 , 10 -20, 100- 200 , 100-, -200 \r\n", |
+ true, |
+ 5, |
+ { |
+ {0, 1, -1}, |
+ {10, 20, -1}, |
+ {100, 200, -1}, |
+ {100, -1, -1}, |
+ {-1, -1, 200}, |
+ }}, |
+ }; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
std::vector<net::HttpByteRange> ranges; |
- bool return_value = HttpUtil::ParseRanges(std::string(tests[i].headers), |
- &ranges); |
+ bool return_value = |
+ HttpUtil::ParseRanges(std::string(tests[i].headers), &ranges); |
EXPECT_EQ(tests[i].expected_return_value, return_value); |
if (return_value) { |
EXPECT_EQ(tests[i].expected_ranges_size, ranges.size()); |
@@ -888,11 +682,11 @@ void CheckCurrentNameValuePair(HttpUtil::NameValuePairsIterator* parser, |
std::string::const_iterator first_value_begin = parser->value_begin(); |
std::string::const_iterator first_value_end = parser->value_end(); |
- ASSERT_EQ(expected_name, std::string(parser->name_begin(), |
- parser->name_end())); |
+ ASSERT_EQ(expected_name, |
+ std::string(parser->name_begin(), parser->name_end())); |
ASSERT_EQ(expected_name, parser->name()); |
- ASSERT_EQ(expected_value, std::string(parser->value_begin(), |
- parser->value_end())); |
+ ASSERT_EQ(expected_value, |
+ std::string(parser->value_begin(), parser->value_end())); |
ASSERT_EQ(expected_value, parser->value()); |
// Make sure they didn't/don't change. |
@@ -911,22 +705,18 @@ void CheckNextNameValuePair(HttpUtil::NameValuePairsIterator* parser, |
return; |
} |
- CheckCurrentNameValuePair(parser, |
- expect_valid, |
- expected_name, |
- expected_value); |
+ CheckCurrentNameValuePair( |
+ parser, expect_valid, expected_name, expected_value); |
} |
void CheckInvalidNameValuePair(std::string valid_part, |
std::string invalid_part) { |
std::string whole_string = valid_part + invalid_part; |
- HttpUtil::NameValuePairsIterator valid_parser(valid_part.begin(), |
- valid_part.end(), |
- ';'); |
- HttpUtil::NameValuePairsIterator invalid_parser(whole_string.begin(), |
- whole_string.end(), |
- ';'); |
+ HttpUtil::NameValuePairsIterator valid_parser( |
+ valid_part.begin(), valid_part.end(), ';'); |
+ HttpUtil::NameValuePairsIterator invalid_parser( |
+ whole_string.begin(), whole_string.end(), ';'); |
ASSERT_TRUE(valid_parser.valid()); |
ASSERT_TRUE(invalid_parser.valid()); |
@@ -997,10 +787,11 @@ TEST(HttpUtilTest, NameValuePairsIteratorEmptyInput) { |
} |
TEST(HttpUtilTest, NameValuePairsIterator) { |
- std::string data = "alpha=1; beta= 2 ;cappa =' 3; ';" |
- "delta= \" \\\"4\\\" \"; e= \" '5'\"; e=6;" |
- "f='\\'\\h\\e\\l\\l\\o\\ \\w\\o\\r\\l\\d\\'';" |
- "g=''; h='hello'"; |
+ std::string data = |
+ "alpha=1; beta= 2 ;cappa =' 3; ';" |
+ "delta= \" \\\"4\\\" \"; e= \" '5'\"; e=6;" |
+ "f='\\'\\h\\e\\l\\l\\o\\ \\w\\o\\r\\l\\d\\'';" |
+ "g=''; h='hello'"; |
HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
EXPECT_TRUE(parser.valid()); |
@@ -1033,8 +824,8 @@ TEST(HttpUtilTest, NameValuePairsIteratorIllegalInputs) { |
ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; 'beta'=2")); |
ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "'beta'=2")); |
ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", ";beta=")); |
- ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", |
- ";beta=;cappa=2")); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CheckInvalidNameValuePair("alpha=1", ";beta=;cappa=2")); |
// According to the spec this is an error, but it doesn't seem appropriate to |
// change our behaviour to be less permissive at this time. |