summaryrefslogtreecommitdiffstats
path: root/net/http/http_util_unittest.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-06 01:00:53 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-06 01:00:53 +0000
commit036d87726035ac500ba35ab41fdc9ef6128f0e4f (patch)
tree48f2abffad974fd7599616cd2fa7888f2a5d7fe8 /net/http/http_util_unittest.cc
parent9b323e40ae67692745459f68920f5dab61aaaed3 (diff)
downloadchromium_src-036d87726035ac500ba35ab41fdc9ef6128f0e4f.zip
chromium_src-036d87726035ac500ba35ab41fdc9ef6128f0e4f.tar.gz
chromium_src-036d87726035ac500ba35ab41fdc9ef6128f0e4f.tar.bz2
[new http] Normalize line continuations in response headers.
BUG=1272571 Review URL: http://codereview.chromium.org/458 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1818 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_util_unittest.cc')
-rw-r--r--net/http/http_util_unittest.cc235
1 files changed, 235 insertions, 0 deletions
diff --git a/net/http/http_util_unittest.cc b/net/http/http_util_unittest.cc
index 84777f9..aaff8f5 100644
--- a/net/http/http_util_unittest.cc
+++ b/net/http/http_util_unittest.cc
@@ -124,6 +124,241 @@ TEST(HttpUtilTest, AssembleRawHeaders) {
{ "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\tcontinuation|"
+ "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\t\t\tcontinuation|"
+ "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 \t \t 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\tcontinuation2 continuation3|"
+ "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||",
+ },
+
};
for (size_t i = 0; i < arraysize(tests); ++i) {
int input_len = static_cast<int>(strlen(tests[i].input));