summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-08 20:49:51 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-08 20:49:51 +0000
commite9fe92b3357e9010d14dcf628fe3dd7dad830a20 (patch)
treef4427b8ab9d2dae2be9a6db2eb68a97e01c31003 /net
parent0a107b357c4d8a58085f46a98af51d7414ab6c76 (diff)
downloadchromium_src-e9fe92b3357e9010d14dcf628fe3dd7dad830a20.zip
chromium_src-e9fe92b3357e9010d14dcf628fe3dd7dad830a20.tar.gz
chromium_src-e9fe92b3357e9010d14dcf628fe3dd7dad830a20.tar.bz2
Normalize leading LWS in line continuations, per Wan-Teh's suggestion.
Review URL: http://codereview.chromium.org/1802 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1861 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_util.cc31
-rw-r--r--net/http/http_util_unittest.cc54
2 files changed, 70 insertions, 15 deletions
diff --git a/net/http/http_util.cc b/net/http/http_util.cc
index 7d2bf4a..0cf8c23 100644
--- a/net/http/http_util.cc
+++ b/net/http/http_util.cc
@@ -284,6 +284,15 @@ static const char* FindStatusLineEnd(const char* begin, const char* end) {
return begin + i;
}
+// Helper used by AssembleRawHeaders, to skip past leading LWS.
+static const char* FindFirstNonLWS(const char* begin, const char* end) {
+ for (const char* cur = begin; cur != end; ++cur) {
+ if (!HttpUtil::IsLWS(*cur))
+ return cur;
+ }
+ return end; // Not found.
+}
+
std::string HttpUtil::AssembleRawHeaders(const char* input_begin,
int input_len) {
std::string raw_headers;
@@ -303,24 +312,26 @@ std::string HttpUtil::AssembleRawHeaders(const char* input_begin,
CStringTokenizer lines(status_line_end, input_end, "\r\n");
// This variable is true when the previous line was continuable.
- bool can_append_continuation = false;
+ bool prev_line_continuable = false;
while (lines.GetNext()) {
const char* line_begin = lines.token_begin();
const char* line_end = lines.token_end();
- bool is_continuation = can_append_continuation && IsLWS(*line_begin);
-
- // Terminate the previous line.
- if (!is_continuation)
+ if (prev_line_continuable && IsLWS(*line_begin)) {
+ // Join continuation; reduce the leading LWS to a single SP.
+ raw_headers.push_back(' ');
+ raw_headers.append(FindFirstNonLWS(line_begin, line_end), line_end);
+ } else {
+ // Terminate the previous line.
raw_headers.push_back('\0');
- // Copy the raw data to output.
- raw_headers.append(line_begin, line_end);
+ // Copy the raw data to output.
+ raw_headers.append(line_begin, line_end);
- // Check if the current line can be continued.
- if (!is_continuation)
- can_append_continuation = IsLineSegmentContinuable(line_begin, line_end);
+ // Check if the current line can be continued.
+ prev_line_continuable = IsLineSegmentContinuable(line_begin, line_end);
+ }
}
raw_headers.append("\0\0", 2);
diff --git a/net/http/http_util_unittest.cc b/net/http/http_util_unittest.cc
index aaff8f5..14c7724 100644
--- a/net/http/http_util_unittest.cc
+++ b/net/http/http_util_unittest.cc
@@ -145,7 +145,7 @@ TEST(HttpUtilTest, AssembleRawHeaders) {
"Bar: 2\n\n",
"HTTP/1.0 200 OK|"
- "Foo: 1\tcontinuation|"
+ "Foo: 1 continuation|"
"Bar: 2||"
},
@@ -157,7 +157,7 @@ TEST(HttpUtilTest, AssembleRawHeaders) {
"Bar: 2\n\n",
"HTTP/1.0 200 OK|"
- "Foo: 1 continuation|"
+ "Foo: 1 continuation|"
"Bar: 2||"
},
@@ -169,7 +169,7 @@ TEST(HttpUtilTest, AssembleRawHeaders) {
"Bar: 2\n\n",
"HTTP/1.0 200 OK|"
- "Foo: 1\t\t\tcontinuation|"
+ "Foo: 1 continuation|"
"Bar: 2||"
},
@@ -181,7 +181,7 @@ TEST(HttpUtilTest, AssembleRawHeaders) {
"Bar: 2\n\n",
"HTTP/1.0 200 OK|"
- "Foo: 1 \t \t continuation|"
+ "Foo: 1 continuation|"
"Bar: 2||"
},
@@ -195,7 +195,51 @@ TEST(HttpUtilTest, AssembleRawHeaders) {
"Bar: 2\n\n",
"HTTP/1.0 200 OK|"
- "Foo: 1 continuation1\tcontinuation2 continuation3|"
+ "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||"
},