Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: net/http/http_util_unittest.cc

Issue 458: [new http] Normalize line continuations in response headers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "net/http/http_util.h" 8 #include "net/http/http_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 TEST(HttpUtilTest, AssembleRawHeaders) { 117 TEST(HttpUtilTest, AssembleRawHeaders) {
118 struct { 118 struct {
119 const char* input; 119 const char* input;
120 const char* expected_result; // with '\0' changed to '|' 120 const char* expected_result; // with '\0' changed to '|'
121 } tests[] = { 121 } tests[] = {
122 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", 122 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n",
123 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, 123 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" },
124 124
125 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", 125 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n",
126 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, 126 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" },
127
128 // Valid line continuation (single SP).
129 {
130 "HTTP/1.0 200 OK\n"
131 "Foo: 1\n"
132 " continuation\n"
133 "Bar: 2\n\n",
134
135 "HTTP/1.0 200 OK|"
136 "Foo: 1 continuation|"
137 "Bar: 2||"
138 },
139
140 // Valid line continuation (single HT).
141 {
142 "HTTP/1.0 200 OK\n"
143 "Foo: 1\n"
144 "\tcontinuation\n"
145 "Bar: 2\n\n",
146
147 "HTTP/1.0 200 OK|"
148 "Foo: 1\tcontinuation|"
149 "Bar: 2||"
150 },
151
152 // Valid line continuation (multiple SP).
153 {
154 "HTTP/1.0 200 OK\n"
155 "Foo: 1\n"
156 " continuation\n"
157 "Bar: 2\n\n",
158
159 "HTTP/1.0 200 OK|"
160 "Foo: 1 continuation|"
161 "Bar: 2||"
162 },
163
164 // Valid line continuation (multiple HT).
165 {
166 "HTTP/1.0 200 OK\n"
167 "Foo: 1\n"
168 "\t\t\tcontinuation\n"
169 "Bar: 2\n\n",
170
171 "HTTP/1.0 200 OK|"
172 "Foo: 1\t\t\tcontinuation|"
173 "Bar: 2||"
174 },
175
176 // Valid line continuation (mixed HT, SP).
177 {
178 "HTTP/1.0 200 OK\n"
179 "Foo: 1\n"
180 " \t \t continuation\n"
181 "Bar: 2\n\n",
182
183 "HTTP/1.0 200 OK|"
184 "Foo: 1 \t \t continuation|"
185 "Bar: 2||"
186 },
187
188 // Valid multi-line continuation
189 {
190 "HTTP/1.0 200 OK\n"
191 "Foo: 1\n"
192 " continuation1\n"
193 "\tcontinuation2\n"
194 " continuation3\n"
195 "Bar: 2\n\n",
196
197 "HTTP/1.0 200 OK|"
198 "Foo: 1 continuation1\tcontinuation2 continuation3|"
199 "Bar: 2||"
200 },
201
202 // Valid line continuation (No value bytes in first line).
203 {
204 "HTTP/1.0 200 OK\n"
205 "Foo:\n"
206 " value\n"
207 "Bar: 2\n\n",
208
209 "HTTP/1.0 200 OK|"
210 "Foo: value|"
211 "Bar: 2||"
212 },
213
214 // Not a line continuation (can't continue status line).
215 {
216 "HTTP/1.0 200 OK\n"
217 " Foo: 1\n"
218 "Bar: 2\n\n",
219
220 "HTTP/1.0 200 OK|"
221 " Foo: 1|"
222 "Bar: 2||"
223 },
224
225 // Not a line continuation (can't continue status line).
226 {
227 "HTTP/1.0\n"
228 " 200 OK\n"
229 "Foo: 1\n"
230 "Bar: 2\n\n",
231
232 "HTTP/1.0|"
233 " 200 OK|"
234 "Foo: 1|"
235 "Bar: 2||"
236 },
237
238 // Not a line continuation (can't continue status line).
239 {
240 "HTTP/1.0 404\n"
241 " Not Found\n"
242 "Foo: 1\n"
243 "Bar: 2\n\n",
244
245 "HTTP/1.0 404|"
246 " Not Found|"
247 "Foo: 1|"
248 "Bar: 2||"
249 },
250
251 // Unterminated status line.
252 {
253 "HTTP/1.0 200 OK",
254
255 "HTTP/1.0 200 OK||"
256 },
257
258 // Single terminated, with headers
259 {
260 "HTTP/1.0 200 OK\n"
261 "Foo: 1\n"
262 "Bar: 2\n",
263
264 "HTTP/1.0 200 OK|"
265 "Foo: 1|"
266 "Bar: 2||"
267 },
268
269 // Not terminated, with headers
270 {
271 "HTTP/1.0 200 OK\n"
272 "Foo: 1\n"
273 "Bar: 2",
274
275 "HTTP/1.0 200 OK|"
276 "Foo: 1|"
277 "Bar: 2||"
278 },
279
280 // Not a line continuation (VT)
281 {
282 "HTTP/1.0 200 OK\n"
283 "Foo: 1\n"
284 "\vInvalidContinuation\n"
285 "Bar: 2\n\n",
286
287 "HTTP/1.0 200 OK|"
288 "Foo: 1|"
289 "\vInvalidContinuation|"
290 "Bar: 2||"
291 },
292
293 // Not a line continuation (formfeed)
294 {
295 "HTTP/1.0 200 OK\n"
296 "Foo: 1\n"
297 "\fInvalidContinuation\n"
298 "Bar: 2\n\n",
299
300 "HTTP/1.0 200 OK|"
301 "Foo: 1|"
302 "\fInvalidContinuation|"
303 "Bar: 2||"
304 },
305
306 // Not a line continuation -- can't continue header names.
307 {
308 "HTTP/1.0 200 OK\n"
309 "Serv\n"
310 " er: Apache\n"
311 "\tInvalidContinuation\n"
312 "Bar: 2\n\n",
313
314 "HTTP/1.0 200 OK|"
315 "Serv|"
316 " er: Apache|"
317 "\tInvalidContinuation|"
318 "Bar: 2||"
319 },
320
321 // Not a line continuation -- no value to continue.
322 {
323 "HTTP/1.0 200 OK\n"
324 "Foo: 1\n"
325 "garbage\n"
326 " not-a-continuation\n"
327 "Bar: 2\n\n",
328
329 "HTTP/1.0 200 OK|"
330 "Foo: 1|"
331 "garbage|"
332 " not-a-continuation|"
333 "Bar: 2||",
334 },
335
336 // Not a line continuation -- no valid name.
337 {
338 "HTTP/1.0 200 OK\n"
339 ": 1\n"
340 " garbage\n"
341 "Bar: 2\n\n",
342
343 "HTTP/1.0 200 OK|"
344 ": 1|"
345 " garbage|"
346 "Bar: 2||",
347 },
348
349 // Not a line continuation -- no valid name (whitespace)
350 {
351 "HTTP/1.0 200 OK\n"
352 " : 1\n"
353 " garbage\n"
354 "Bar: 2\n\n",
355
356 "HTTP/1.0 200 OK|"
357 " : 1|"
358 " garbage|"
359 "Bar: 2||",
360 },
361
127 }; 362 };
128 for (size_t i = 0; i < arraysize(tests); ++i) { 363 for (size_t i = 0; i < arraysize(tests); ++i) {
129 int input_len = static_cast<int>(strlen(tests[i].input)); 364 int input_len = static_cast<int>(strlen(tests[i].input));
130 std::string raw = HttpUtil::AssembleRawHeaders(tests[i].input, input_len); 365 std::string raw = HttpUtil::AssembleRawHeaders(tests[i].input, input_len);
131 std::replace(raw.begin(), raw.end(), '\0', '|'); 366 std::replace(raw.begin(), raw.end(), '\0', '|');
132 EXPECT_TRUE(raw == tests[i].expected_result); 367 EXPECT_TRUE(raw == tests[i].expected_result);
133 } 368 }
134 } 369 }
135 370
OLDNEW
« no previous file with comments | « net/http/http_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698