Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/string_util.h" | 7 #include "base/strings/string_util.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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 {"foo\nbar\n\r\njunk", 10}, | 371 {"foo\nbar\n\r\njunk", 10}, |
| 372 {"foo\nbar\r\n\njunk", 10}, | 372 {"foo\nbar\r\n\njunk", 10}, |
| 373 }; | 373 }; |
| 374 for (size_t i = 0; i < arraysize(tests); ++i) { | 374 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 375 int input_len = static_cast<int>(strlen(tests[i].input)); | 375 int input_len = static_cast<int>(strlen(tests[i].input)); |
| 376 int eoh = HttpUtil::LocateEndOfAdditionalHeaders(tests[i].input, input_len); | 376 int eoh = HttpUtil::LocateEndOfAdditionalHeaders(tests[i].input, input_len); |
| 377 EXPECT_EQ(tests[i].expected_result, eoh); | 377 EXPECT_EQ(tests[i].expected_result, eoh); |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 TEST(HttpUtilTest, AssembleRawHeaders) { | 380 TEST(HttpUtilTest, AssembleRawHeaders) { |
| 381 // clang-format off | |
| 381 struct { | 382 struct { |
| 382 const char* const input; // with '|' representing '\0' | 383 const char* const input; // with '|' representing '\0' |
| 383 const char* const expected_result; // with '\0' changed to '|' | 384 const char* const expected_result; // with '\0' changed to '|' |
| 384 } tests[] = { | 385 } tests[] = { |
| 385 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", | 386 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", |
| 386 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, | 387 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, |
| 387 | 388 |
| 388 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", | 389 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", |
| 389 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, | 390 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, |
| 390 | 391 |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 "HTTP/1.0 200 OK|Bar2:0|Baz2:1\r\nFoo: 1\r\nBar: 2\r\n\r\n", | 673 "HTTP/1.0 200 OK|Bar2:0|Baz2:1\r\nFoo: 1\r\nBar: 2\r\n\r\n", |
| 673 "HTTP/1.0 200 OKBar2:0Baz2:1|Foo: 1|Bar: 2||" | 674 "HTTP/1.0 200 OKBar2:0Baz2:1|Foo: 1|Bar: 2||" |
| 674 }, | 675 }, |
| 675 | 676 |
| 676 // Embed NULLs in a header line. They should not be understood as | 677 // Embed NULLs in a header line. They should not be understood as |
| 677 // line separators. | 678 // line separators. |
| 678 { | 679 { |
| 679 "HTTP/1.0 200 OK\nFoo: 1|Foo2: 3\nBar: 2\n\n", | 680 "HTTP/1.0 200 OK\nFoo: 1|Foo2: 3\nBar: 2\n\n", |
| 680 "HTTP/1.0 200 OK|Foo: 1Foo2: 3|Bar: 2||" | 681 "HTTP/1.0 200 OK|Foo: 1Foo2: 3|Bar: 2||" |
| 681 }, | 682 }, |
| 683 | |
| 684 // An embedded NUL should not be interpreted as LWS (leading to line | |
| 685 // continuations) | |
| 686 { | |
| 687 "HTTP/1.0 200 OK\n" | |
| 688 "Foo: 1\n" | |
| 689 "|EmbeddedNull: 3\n" | |
| 690 "Bar: 2\n\n", | |
| 691 "HTTP/1.0 200 OK|Foo: 1|EmbeddedNull: 3|Bar: 2||" | |
|
mmenke
2016/12/06 19:08:24
EmbeddedNull? Where's the magic for that.
eroman
2016/12/06 19:19:34
There is nothing special about "EmbeddedNull", I j
eroman
2016/12/06 19:25:33
Want me to rename this to something more generic l
eroman
2016/12/06 19:29:00
Done.
| |
| 692 }, | |
| 682 }; | 693 }; |
| 694 // clang-format on | |
| 683 for (size_t i = 0; i < arraysize(tests); ++i) { | 695 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 684 std::string input = tests[i].input; | 696 std::string input = tests[i].input; |
| 685 std::replace(input.begin(), input.end(), '|', '\0'); | 697 std::replace(input.begin(), input.end(), '|', '\0'); |
| 686 std::string raw = HttpUtil::AssembleRawHeaders(input.data(), input.size()); | 698 std::string raw = HttpUtil::AssembleRawHeaders(input.data(), input.size()); |
| 687 std::replace(raw.begin(), raw.end(), '\0', '|'); | 699 std::replace(raw.begin(), raw.end(), '\0', '|'); |
| 688 EXPECT_EQ(tests[i].expected_result, raw); | 700 EXPECT_EQ(tests[i].expected_result, raw); |
| 689 } | 701 } |
| 690 } | 702 } |
| 691 | 703 |
| 692 // Test SpecForRequest(). | 704 // Test SpecForRequest(). |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1401 EXPECT_FALSE(HttpUtil::IsToken(base::StringPiece())); | 1413 EXPECT_FALSE(HttpUtil::IsToken(base::StringPiece())); |
| 1402 EXPECT_FALSE(HttpUtil::IsToken("hello, world")); | 1414 EXPECT_FALSE(HttpUtil::IsToken("hello, world")); |
| 1403 EXPECT_FALSE(HttpUtil::IsToken(" ")); | 1415 EXPECT_FALSE(HttpUtil::IsToken(" ")); |
| 1404 EXPECT_FALSE(HttpUtil::IsToken(base::StringPiece("\0", 1))); | 1416 EXPECT_FALSE(HttpUtil::IsToken(base::StringPiece("\0", 1))); |
| 1405 EXPECT_FALSE(HttpUtil::IsToken("\x01")); | 1417 EXPECT_FALSE(HttpUtil::IsToken("\x01")); |
| 1406 EXPECT_FALSE(HttpUtil::IsToken("\x7F")); | 1418 EXPECT_FALSE(HttpUtil::IsToken("\x7F")); |
| 1407 EXPECT_FALSE(HttpUtil::IsToken("\x80")); | 1419 EXPECT_FALSE(HttpUtil::IsToken("\x80")); |
| 1408 EXPECT_FALSE(HttpUtil::IsToken("\xff")); | 1420 EXPECT_FALSE(HttpUtil::IsToken("\xff")); |
| 1409 } | 1421 } |
| 1410 | 1422 |
| 1423 TEST(HttpUtilTest, IsLWS) { | |
| 1424 EXPECT_FALSE(HttpUtil::IsLWS('\v')); | |
| 1425 EXPECT_FALSE(HttpUtil::IsLWS('\0')); | |
| 1426 EXPECT_FALSE(HttpUtil::IsLWS('1')); | |
| 1427 EXPECT_FALSE(HttpUtil::IsLWS('a')); | |
| 1428 EXPECT_FALSE(HttpUtil::IsLWS('.')); | |
| 1429 EXPECT_FALSE(HttpUtil::IsLWS('\n')); | |
| 1430 EXPECT_FALSE(HttpUtil::IsLWS('\r')); | |
| 1431 | |
| 1432 EXPECT_TRUE(HttpUtil::IsLWS('\t')); | |
| 1433 EXPECT_TRUE(HttpUtil::IsLWS(' ')); | |
|
mmenke
2016/12/06 19:08:24
Should we have a whitelist here? i.e.
for (int c
eroman
2016/12/06 19:19:34
I think that is a bit overkill, but can switch to
mmenke
2016/12/06 19:25:29
ok
| |
| 1434 } | |
| 1435 | |
| 1411 } // namespace net | 1436 } // namespace net |
| OLD | NEW |