| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 if (!headers->empty()) | 44 if (!headers->empty()) |
| 45 *headers += '\0'; | 45 *headers += '\0'; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void TestCommon(const TestData& test) { | 48 void TestCommon(const TestData& test) { |
| 49 string raw_headers(test.raw_headers); | 49 string raw_headers(test.raw_headers); |
| 50 HeadersToRaw(&raw_headers); | 50 HeadersToRaw(&raw_headers); |
| 51 string expected_headers(test.expected_headers); | 51 string expected_headers(test.expected_headers); |
| 52 | 52 |
| 53 string headers; | 53 string headers; |
| 54 scoped_refptr<HttpResponseHeaders> parsed = | 54 scoped_refptr<HttpResponseHeaders> parsed( |
| 55 new HttpResponseHeaders(raw_headers); | 55 new HttpResponseHeaders(raw_headers)); |
| 56 parsed->GetNormalizedHeaders(&headers); | 56 parsed->GetNormalizedHeaders(&headers); |
| 57 | 57 |
| 58 // Transform to readable output format (so it's easier to see diffs). | 58 // Transform to readable output format (so it's easier to see diffs). |
| 59 replace(headers.begin(), headers.end(), ' ', '_'); | 59 replace(headers.begin(), headers.end(), ' ', '_'); |
| 60 replace(headers.begin(), headers.end(), '\n', '\\'); | 60 replace(headers.begin(), headers.end(), '\n', '\\'); |
| 61 replace(expected_headers.begin(), expected_headers.end(), ' ', '_'); | 61 replace(expected_headers.begin(), expected_headers.end(), ' ', '_'); |
| 62 replace(expected_headers.begin(), expected_headers.end(), '\n', '\\'); | 62 replace(expected_headers.begin(), expected_headers.end(), '\n', '\\'); |
| 63 | 63 |
| 64 EXPECT_EQ(expected_headers, headers); | 64 EXPECT_EQ(expected_headers, headers); |
| 65 | 65 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 }; | 274 }; |
| 275 TestCommon(test); | 275 TestCommon(test); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST(HttpResponseHeadersTest, GetNormalizedHeader) { | 278 TEST(HttpResponseHeadersTest, GetNormalizedHeader) { |
| 279 std::string headers = | 279 std::string headers = |
| 280 "HTTP/1.1 200 OK\n" | 280 "HTTP/1.1 200 OK\n" |
| 281 "Cache-control: private\n" | 281 "Cache-control: private\n" |
| 282 "cache-Control: no-store\n"; | 282 "cache-Control: no-store\n"; |
| 283 HeadersToRaw(&headers); | 283 HeadersToRaw(&headers); |
| 284 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 284 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 285 | 285 |
| 286 std::string value; | 286 std::string value; |
| 287 EXPECT_TRUE(parsed->GetNormalizedHeader("cache-control", &value)); | 287 EXPECT_TRUE(parsed->GetNormalizedHeader("cache-control", &value)); |
| 288 EXPECT_EQ("private, no-store", value); | 288 EXPECT_EQ("private, no-store", value); |
| 289 } | 289 } |
| 290 | 290 |
| 291 TEST(HttpResponseHeadersTest, Persist) { | 291 TEST(HttpResponseHeadersTest, Persist) { |
| 292 const struct { | 292 const struct { |
| 293 net::HttpResponseHeaders::PersistOptions options; | 293 net::HttpResponseHeaders::PersistOptions options; |
| 294 const char* raw_headers; | 294 const char* raw_headers; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 441 |
| 442 "HTTP/1.1 200 OK\n" | 442 "HTTP/1.1 200 OK\n" |
| 443 "Content-Length: 450\n" | 443 "Content-Length: 450\n" |
| 444 "Content-Encoding: gzip\n" | 444 "Content-Encoding: gzip\n" |
| 445 }, | 445 }, |
| 446 }; | 446 }; |
| 447 | 447 |
| 448 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 448 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 449 std::string headers = tests[i].raw_headers; | 449 std::string headers = tests[i].raw_headers; |
| 450 HeadersToRaw(&headers); | 450 HeadersToRaw(&headers); |
| 451 scoped_refptr<HttpResponseHeaders> parsed1 = | 451 scoped_refptr<HttpResponseHeaders> parsed1( |
| 452 new HttpResponseHeaders(headers); | 452 new HttpResponseHeaders(headers)); |
| 453 | 453 |
| 454 Pickle pickle; | 454 Pickle pickle; |
| 455 parsed1->Persist(&pickle, tests[i].options); | 455 parsed1->Persist(&pickle, tests[i].options); |
| 456 | 456 |
| 457 void* iter = NULL; | 457 void* iter = NULL; |
| 458 scoped_refptr<HttpResponseHeaders> parsed2 = | 458 scoped_refptr<HttpResponseHeaders> parsed2( |
| 459 new HttpResponseHeaders(pickle, &iter); | 459 new HttpResponseHeaders(pickle, &iter)); |
| 460 | 460 |
| 461 std::string h2; | 461 std::string h2; |
| 462 parsed2->GetNormalizedHeaders(&h2); | 462 parsed2->GetNormalizedHeaders(&h2); |
| 463 EXPECT_EQ(string(tests[i].expected_headers), h2); | 463 EXPECT_EQ(string(tests[i].expected_headers), h2); |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 | 466 |
| 467 TEST(HttpResponseHeadersTest, EnumerateHeader_Coalesced) { | 467 TEST(HttpResponseHeadersTest, EnumerateHeader_Coalesced) { |
| 468 // Ensure that commas in quoted strings are not regarded as value separators. | 468 // Ensure that commas in quoted strings are not regarded as value separators. |
| 469 // Ensure that whitespace following a value is trimmed properly | 469 // Ensure that whitespace following a value is trimmed properly |
| 470 std::string headers = | 470 std::string headers = |
| 471 "HTTP/1.1 200 OK\n" | 471 "HTTP/1.1 200 OK\n" |
| 472 "Cache-control:private , no-cache=\"set-cookie,server\" \n" | 472 "Cache-control:private , no-cache=\"set-cookie,server\" \n" |
| 473 "cache-Control: no-store\n"; | 473 "cache-Control: no-store\n"; |
| 474 HeadersToRaw(&headers); | 474 HeadersToRaw(&headers); |
| 475 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 475 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 476 | 476 |
| 477 void* iter = NULL; | 477 void* iter = NULL; |
| 478 std::string value; | 478 std::string value; |
| 479 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); | 479 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); |
| 480 EXPECT_EQ("private", value); | 480 EXPECT_EQ("private", value); |
| 481 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); | 481 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); |
| 482 EXPECT_EQ("no-cache=\"set-cookie,server\"", value); | 482 EXPECT_EQ("no-cache=\"set-cookie,server\"", value); |
| 483 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); | 483 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "cache-control", &value)); |
| 484 EXPECT_EQ("no-store", value); | 484 EXPECT_EQ("no-store", value); |
| 485 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "cache-control", &value)); | 485 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "cache-control", &value)); |
| 486 } | 486 } |
| 487 | 487 |
| 488 TEST(HttpResponseHeadersTest, EnumerateHeader_Challenge) { | 488 TEST(HttpResponseHeadersTest, EnumerateHeader_Challenge) { |
| 489 // Even though WWW-Authenticate has commas, it should not be treated as | 489 // Even though WWW-Authenticate has commas, it should not be treated as |
| 490 // coalesced values. | 490 // coalesced values. |
| 491 std::string headers = | 491 std::string headers = |
| 492 "HTTP/1.1 401 OK\n" | 492 "HTTP/1.1 401 OK\n" |
| 493 "WWW-Authenticate:Digest realm=foobar, nonce=x, domain=y\n" | 493 "WWW-Authenticate:Digest realm=foobar, nonce=x, domain=y\n" |
| 494 "WWW-Authenticate:Basic realm=quatar\n"; | 494 "WWW-Authenticate:Basic realm=quatar\n"; |
| 495 HeadersToRaw(&headers); | 495 HeadersToRaw(&headers); |
| 496 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 496 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 497 | 497 |
| 498 void* iter = NULL; | 498 void* iter = NULL; |
| 499 std::string value; | 499 std::string value; |
| 500 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); | 500 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); |
| 501 EXPECT_EQ("Digest realm=foobar, nonce=x, domain=y", value); | 501 EXPECT_EQ("Digest realm=foobar, nonce=x, domain=y", value); |
| 502 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); | 502 EXPECT_TRUE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); |
| 503 EXPECT_EQ("Basic realm=quatar", value); | 503 EXPECT_EQ("Basic realm=quatar", value); |
| 504 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); | 504 EXPECT_FALSE(parsed->EnumerateHeader(&iter, "WWW-Authenticate", &value)); |
| 505 } | 505 } |
| 506 | 506 |
| 507 TEST(HttpResponseHeadersTest, EnumerateHeader_DateValued) { | 507 TEST(HttpResponseHeadersTest, EnumerateHeader_DateValued) { |
| 508 // The comma in a date valued header should not be treated as a | 508 // The comma in a date valued header should not be treated as a |
| 509 // field-value separator | 509 // field-value separator |
| 510 std::string headers = | 510 std::string headers = |
| 511 "HTTP/1.1 200 OK\n" | 511 "HTTP/1.1 200 OK\n" |
| 512 "Date: Tue, 07 Aug 2007 23:10:55 GMT\n" | 512 "Date: Tue, 07 Aug 2007 23:10:55 GMT\n" |
| 513 "Last-Modified: Wed, 01 Aug 2007 23:23:45 GMT\n"; | 513 "Last-Modified: Wed, 01 Aug 2007 23:23:45 GMT\n"; |
| 514 HeadersToRaw(&headers); | 514 HeadersToRaw(&headers); |
| 515 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 515 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 516 | 516 |
| 517 std::string value; | 517 std::string value; |
| 518 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "date", &value)); | 518 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "date", &value)); |
| 519 EXPECT_EQ("Tue, 07 Aug 2007 23:10:55 GMT", value); | 519 EXPECT_EQ("Tue, 07 Aug 2007 23:10:55 GMT", value); |
| 520 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "last-modified", &value)); | 520 EXPECT_TRUE(parsed->EnumerateHeader(NULL, "last-modified", &value)); |
| 521 EXPECT_EQ("Wed, 01 Aug 2007 23:23:45 GMT", value); | 521 EXPECT_EQ("Wed, 01 Aug 2007 23:23:45 GMT", value); |
| 522 } | 522 } |
| 523 | 523 |
| 524 TEST(HttpResponseHeadersTest, GetMimeType) { | 524 TEST(HttpResponseHeadersTest, GetMimeType) { |
| 525 const ContentTypeTestData tests[] = { | 525 const ContentTypeTestData tests[] = { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 { "HTTP/1.1 200 OK\n" | 649 { "HTTP/1.1 200 OK\n" |
| 650 "Content-type: */*\n", | 650 "Content-type: */*\n", |
| 651 "", false, | 651 "", false, |
| 652 "", false, | 652 "", false, |
| 653 "*/*" }, | 653 "*/*" }, |
| 654 }; | 654 }; |
| 655 | 655 |
| 656 for (size_t i = 0; i < arraysize(tests); ++i) { | 656 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 657 string headers(tests[i].raw_headers); | 657 string headers(tests[i].raw_headers); |
| 658 HeadersToRaw(&headers); | 658 HeadersToRaw(&headers); |
| 659 scoped_refptr<HttpResponseHeaders> parsed = | 659 scoped_refptr<HttpResponseHeaders> parsed( |
| 660 new HttpResponseHeaders(headers); | 660 new HttpResponseHeaders(headers)); |
| 661 | 661 |
| 662 std::string value; | 662 std::string value; |
| 663 EXPECT_EQ(tests[i].has_mimetype, parsed->GetMimeType(&value)); | 663 EXPECT_EQ(tests[i].has_mimetype, parsed->GetMimeType(&value)); |
| 664 EXPECT_EQ(tests[i].mime_type, value); | 664 EXPECT_EQ(tests[i].mime_type, value); |
| 665 value.clear(); | 665 value.clear(); |
| 666 EXPECT_EQ(tests[i].has_charset, parsed->GetCharset(&value)); | 666 EXPECT_EQ(tests[i].has_charset, parsed->GetCharset(&value)); |
| 667 EXPECT_EQ(tests[i].charset, value); | 667 EXPECT_EQ(tests[i].charset, value); |
| 668 EXPECT_TRUE(parsed->GetNormalizedHeader("content-type", &value)); | 668 EXPECT_TRUE(parsed->GetNormalizedHeader("content-type", &value)); |
| 669 EXPECT_EQ(tests[i].all_content_type, value); | 669 EXPECT_EQ(tests[i].all_content_type, value); |
| 670 } | 670 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 // TODO(darin): add many many more tests here | 800 // TODO(darin): add many many more tests here |
| 801 }; | 801 }; |
| 802 Time request_time, response_time, current_time; | 802 Time request_time, response_time, current_time; |
| 803 Time::FromString(L"Wed, 28 Nov 2007 00:40:09 GMT", &request_time); | 803 Time::FromString(L"Wed, 28 Nov 2007 00:40:09 GMT", &request_time); |
| 804 Time::FromString(L"Wed, 28 Nov 2007 00:40:12 GMT", &response_time); | 804 Time::FromString(L"Wed, 28 Nov 2007 00:40:12 GMT", &response_time); |
| 805 Time::FromString(L"Wed, 28 Nov 2007 00:45:20 GMT", ¤t_time); | 805 Time::FromString(L"Wed, 28 Nov 2007 00:45:20 GMT", ¤t_time); |
| 806 | 806 |
| 807 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 807 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 808 string headers(tests[i].headers); | 808 string headers(tests[i].headers); |
| 809 HeadersToRaw(&headers); | 809 HeadersToRaw(&headers); |
| 810 scoped_refptr<HttpResponseHeaders> parsed = | 810 scoped_refptr<HttpResponseHeaders> parsed( |
| 811 new HttpResponseHeaders(headers); | 811 new HttpResponseHeaders(headers)); |
| 812 | 812 |
| 813 bool requires_validation = | 813 bool requires_validation = |
| 814 parsed->RequiresValidation(request_time, response_time, current_time); | 814 parsed->RequiresValidation(request_time, response_time, current_time); |
| 815 EXPECT_EQ(tests[i].requires_validation, requires_validation); | 815 EXPECT_EQ(tests[i].requires_validation, requires_validation); |
| 816 } | 816 } |
| 817 } | 817 } |
| 818 | 818 |
| 819 TEST(HttpResponseHeadersTest, Update) { | 819 TEST(HttpResponseHeadersTest, Update) { |
| 820 const struct { | 820 const struct { |
| 821 const char* orig_headers; | 821 const char* orig_headers; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 | 864 |
| 865 "HTTP/1.1 200 OK\n" | 865 "HTTP/1.1 200 OK\n" |
| 866 "Cache-control: max-age=10001\n" | 866 "Cache-control: max-age=10001\n" |
| 867 "Content-Length: 450\n" | 867 "Content-Length: 450\n" |
| 868 }, | 868 }, |
| 869 }; | 869 }; |
| 870 | 870 |
| 871 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 871 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 872 string orig_headers(tests[i].orig_headers); | 872 string orig_headers(tests[i].orig_headers); |
| 873 HeadersToRaw(&orig_headers); | 873 HeadersToRaw(&orig_headers); |
| 874 scoped_refptr<HttpResponseHeaders> parsed = | 874 scoped_refptr<HttpResponseHeaders> parsed( |
| 875 new HttpResponseHeaders(orig_headers); | 875 new HttpResponseHeaders(orig_headers)); |
| 876 | 876 |
| 877 string new_headers(tests[i].new_headers); | 877 string new_headers(tests[i].new_headers); |
| 878 HeadersToRaw(&new_headers); | 878 HeadersToRaw(&new_headers); |
| 879 scoped_refptr<HttpResponseHeaders> new_parsed = | 879 scoped_refptr<HttpResponseHeaders> new_parsed( |
| 880 new HttpResponseHeaders(new_headers); | 880 new HttpResponseHeaders(new_headers)); |
| 881 | 881 |
| 882 parsed->Update(*new_parsed); | 882 parsed->Update(*new_parsed); |
| 883 | 883 |
| 884 string resulting_headers; | 884 string resulting_headers; |
| 885 parsed->GetNormalizedHeaders(&resulting_headers); | 885 parsed->GetNormalizedHeaders(&resulting_headers); |
| 886 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); | 886 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); |
| 887 } | 887 } |
| 888 } | 888 } |
| 889 | 889 |
| 890 TEST(HttpResponseHeadersTest, EnumerateHeaderLines) { | 890 TEST(HttpResponseHeadersTest, EnumerateHeaderLines) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 910 }, | 910 }, |
| 911 { "HTTP/1.1 200 OK\n" | 911 { "HTTP/1.1 200 OK\n" |
| 912 "Foo: 1, 2, 3\n", | 912 "Foo: 1, 2, 3\n", |
| 913 | 913 |
| 914 "Foo: 1, 2, 3\n" | 914 "Foo: 1, 2, 3\n" |
| 915 }, | 915 }, |
| 916 }; | 916 }; |
| 917 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 917 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 918 string headers(tests[i].headers); | 918 string headers(tests[i].headers); |
| 919 HeadersToRaw(&headers); | 919 HeadersToRaw(&headers); |
| 920 scoped_refptr<HttpResponseHeaders> parsed = | 920 scoped_refptr<HttpResponseHeaders> parsed( |
| 921 new HttpResponseHeaders(headers); | 921 new HttpResponseHeaders(headers)); |
| 922 | 922 |
| 923 string name, value, lines; | 923 string name, value, lines; |
| 924 | 924 |
| 925 void* iter = NULL; | 925 void* iter = NULL; |
| 926 while (parsed->EnumerateHeaderLines(&iter, &name, &value)) { | 926 while (parsed->EnumerateHeaderLines(&iter, &name, &value)) { |
| 927 lines.append(name); | 927 lines.append(name); |
| 928 lines.append(": "); | 928 lines.append(": "); |
| 929 lines.append(value); | 929 lines.append(value); |
| 930 lines.append("\n"); | 930 lines.append("\n"); |
| 931 } | 931 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 }, | 994 }, |
| 995 { "HTTP/1.1 301 Moved\n" | 995 { "HTTP/1.1 301 Moved\n" |
| 996 "Location: http://foo/bar?key=\x83\x5C\x82\x5D\xCB\xD7\n", | 996 "Location: http://foo/bar?key=\x83\x5C\x82\x5D\xCB\xD7\n", |
| 997 "http://foo/bar?key=%83\\%82]%CB%D7", | 997 "http://foo/bar?key=%83\\%82]%CB%D7", |
| 998 true | 998 true |
| 999 }, | 999 }, |
| 1000 }; | 1000 }; |
| 1001 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1001 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1002 string headers(tests[i].headers); | 1002 string headers(tests[i].headers); |
| 1003 HeadersToRaw(&headers); | 1003 HeadersToRaw(&headers); |
| 1004 scoped_refptr<HttpResponseHeaders> parsed = | 1004 scoped_refptr<HttpResponseHeaders> parsed( |
| 1005 new HttpResponseHeaders(headers); | 1005 new HttpResponseHeaders(headers)); |
| 1006 | 1006 |
| 1007 std::string location; | 1007 std::string location; |
| 1008 EXPECT_EQ(parsed->IsRedirect(&location), tests[i].is_redirect); | 1008 EXPECT_EQ(parsed->IsRedirect(&location), tests[i].is_redirect); |
| 1009 EXPECT_EQ(location, tests[i].location); | 1009 EXPECT_EQ(location, tests[i].location); |
| 1010 } | 1010 } |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 TEST(HttpResponseHeadersTest, GetContentLength) { | 1013 TEST(HttpResponseHeadersTest, GetContentLength) { |
| 1014 const struct { | 1014 const struct { |
| 1015 const char* headers; | 1015 const char* headers; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 33 | 1080 33 |
| 1081 }, | 1081 }, |
| 1082 { "HTTP/1.1 200 OK\n" | 1082 { "HTTP/1.1 200 OK\n" |
| 1083 "Content-Length: 34\r\n", | 1083 "Content-Length: 34\r\n", |
| 1084 -1 | 1084 -1 |
| 1085 }, | 1085 }, |
| 1086 }; | 1086 }; |
| 1087 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1087 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1088 string headers(tests[i].headers); | 1088 string headers(tests[i].headers); |
| 1089 HeadersToRaw(&headers); | 1089 HeadersToRaw(&headers); |
| 1090 scoped_refptr<HttpResponseHeaders> parsed = | 1090 scoped_refptr<HttpResponseHeaders> parsed( |
| 1091 new HttpResponseHeaders(headers); | 1091 new HttpResponseHeaders(headers)); |
| 1092 | 1092 |
| 1093 EXPECT_EQ(tests[i].expected_len, parsed->GetContentLength()); | 1093 EXPECT_EQ(tests[i].expected_len, parsed->GetContentLength()); |
| 1094 } | 1094 } |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 TEST(HttpResponseHeaders, GetContentRange) { | 1097 TEST(HttpResponseHeaders, GetContentRange) { |
| 1098 const struct { | 1098 const struct { |
| 1099 const char* headers; | 1099 const char* headers; |
| 1100 bool expected_return_value; | 1100 bool expected_return_value; |
| 1101 int64 expected_first_byte_position; | 1101 int64 expected_first_byte_position; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 "Content-Range: bytes -123 - -1/100", | 1331 "Content-Range: bytes -123 - -1/100", |
| 1332 false, | 1332 false, |
| 1333 -1, | 1333 -1, |
| 1334 -1, | 1334 -1, |
| 1335 -1 | 1335 -1 |
| 1336 }, | 1336 }, |
| 1337 }; | 1337 }; |
| 1338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1338 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1339 string headers(tests[i].headers); | 1339 string headers(tests[i].headers); |
| 1340 HeadersToRaw(&headers); | 1340 HeadersToRaw(&headers); |
| 1341 scoped_refptr<HttpResponseHeaders> parsed = | 1341 scoped_refptr<HttpResponseHeaders> parsed( |
| 1342 new HttpResponseHeaders(headers); | 1342 new HttpResponseHeaders(headers)); |
| 1343 | 1343 |
| 1344 int64 first_byte_position; | 1344 int64 first_byte_position; |
| 1345 int64 last_byte_position; | 1345 int64 last_byte_position; |
| 1346 int64 instance_size; | 1346 int64 instance_size; |
| 1347 bool return_value = parsed->GetContentRange(&first_byte_position, | 1347 bool return_value = parsed->GetContentRange(&first_byte_position, |
| 1348 &last_byte_position, | 1348 &last_byte_position, |
| 1349 &instance_size); | 1349 &instance_size); |
| 1350 EXPECT_EQ(tests[i].expected_return_value, return_value); | 1350 EXPECT_EQ(tests[i].expected_return_value, return_value); |
| 1351 EXPECT_EQ(tests[i].expected_first_byte_position, first_byte_position); | 1351 EXPECT_EQ(tests[i].expected_first_byte_position, first_byte_position); |
| 1352 EXPECT_EQ(tests[i].expected_last_byte_position, last_byte_position); | 1352 EXPECT_EQ(tests[i].expected_last_byte_position, last_byte_position); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 false | 1413 false |
| 1414 }, | 1414 }, |
| 1415 { "HTTP/1.1 200 OK\n" | 1415 { "HTTP/1.1 200 OK\n" |
| 1416 "proxy-connection: keep-alive\n", | 1416 "proxy-connection: keep-alive\n", |
| 1417 true | 1417 true |
| 1418 }, | 1418 }, |
| 1419 }; | 1419 }; |
| 1420 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1420 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1421 string headers(tests[i].headers); | 1421 string headers(tests[i].headers); |
| 1422 HeadersToRaw(&headers); | 1422 HeadersToRaw(&headers); |
| 1423 scoped_refptr<HttpResponseHeaders> parsed = | 1423 scoped_refptr<HttpResponseHeaders> parsed( |
| 1424 new HttpResponseHeaders(headers); | 1424 new HttpResponseHeaders(headers)); |
| 1425 | 1425 |
| 1426 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); | 1426 EXPECT_EQ(tests[i].expected_keep_alive, parsed->IsKeepAlive()); |
| 1427 } | 1427 } |
| 1428 } | 1428 } |
| 1429 | 1429 |
| 1430 TEST(HttpResponseHeadersTest, HasStrongValidators) { | 1430 TEST(HttpResponseHeadersTest, HasStrongValidators) { |
| 1431 const struct { | 1431 const struct { |
| 1432 const char* headers; | 1432 const char* headers; |
| 1433 bool expected_result; | 1433 bool expected_result; |
| 1434 } tests[] = { | 1434 } tests[] = { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 false | 1466 false |
| 1467 }, | 1467 }, |
| 1468 { "HTTP/1.1 200 OK\n" | 1468 { "HTTP/1.1 200 OK\n" |
| 1469 "etag: W / \"foo\"\n", | 1469 "etag: W / \"foo\"\n", |
| 1470 false | 1470 false |
| 1471 } | 1471 } |
| 1472 }; | 1472 }; |
| 1473 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1473 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1474 string headers(tests[i].headers); | 1474 string headers(tests[i].headers); |
| 1475 HeadersToRaw(&headers); | 1475 HeadersToRaw(&headers); |
| 1476 scoped_refptr<HttpResponseHeaders> parsed = | 1476 scoped_refptr<HttpResponseHeaders> parsed( |
| 1477 new HttpResponseHeaders(headers); | 1477 new HttpResponseHeaders(headers)); |
| 1478 | 1478 |
| 1479 EXPECT_EQ(tests[i].expected_result, parsed->HasStrongValidators()) << | 1479 EXPECT_EQ(tests[i].expected_result, parsed->HasStrongValidators()) << |
| 1480 "Failed test case " << i; | 1480 "Failed test case " << i; |
| 1481 } | 1481 } |
| 1482 } | 1482 } |
| 1483 | 1483 |
| 1484 TEST(HttpResponseHeadersTest, GetStatusText) { | 1484 TEST(HttpResponseHeadersTest, GetStatusText) { |
| 1485 std::string headers("HTTP/1.1 404 Not Found"); | 1485 std::string headers("HTTP/1.1 404 Not Found"); |
| 1486 HeadersToRaw(&headers); | 1486 HeadersToRaw(&headers); |
| 1487 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 1487 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 1488 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); | 1488 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); |
| 1489 } | 1489 } |
| 1490 | 1490 |
| 1491 TEST(HttpResponseHeadersTest, GetStatusTextMissing) { | 1491 TEST(HttpResponseHeadersTest, GetStatusTextMissing) { |
| 1492 std::string headers("HTTP/1.1 404"); | 1492 std::string headers("HTTP/1.1 404"); |
| 1493 HeadersToRaw(&headers); | 1493 HeadersToRaw(&headers); |
| 1494 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 1494 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 1495 // Since the status line gets normalized, we have OK | 1495 // Since the status line gets normalized, we have OK |
| 1496 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); | 1496 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 TEST(HttpResponseHeadersTest, GetStatusTextMultiSpace) { | 1499 TEST(HttpResponseHeadersTest, GetStatusTextMultiSpace) { |
| 1500 std::string headers("HTTP/1.0 404 Not Found"); | 1500 std::string headers("HTTP/1.0 404 Not Found"); |
| 1501 HeadersToRaw(&headers); | 1501 HeadersToRaw(&headers); |
| 1502 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 1502 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 1503 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); | 1503 EXPECT_EQ(std::string("Not Found"), parsed->GetStatusText()); |
| 1504 } | 1504 } |
| 1505 | 1505 |
| 1506 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { | 1506 TEST(HttpResponseHeadersTest, GetStatusBadStatusLine) { |
| 1507 std::string headers("Foo bar."); | 1507 std::string headers("Foo bar."); |
| 1508 HeadersToRaw(&headers); | 1508 HeadersToRaw(&headers); |
| 1509 scoped_refptr<HttpResponseHeaders> parsed = new HttpResponseHeaders(headers); | 1509 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
| 1510 // The bad status line would have gotten rewritten as | 1510 // The bad status line would have gotten rewritten as |
| 1511 // HTTP/1.0 200 OK. | 1511 // HTTP/1.0 200 OK. |
| 1512 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); | 1512 EXPECT_EQ(std::string("OK"), parsed->GetStatusText()); |
| 1513 } | 1513 } |
| 1514 | 1514 |
| 1515 TEST(HttpResponseHeadersTest, AddHeader) { | 1515 TEST(HttpResponseHeadersTest, AddHeader) { |
| 1516 const struct { | 1516 const struct { |
| 1517 const char* orig_headers; | 1517 const char* orig_headers; |
| 1518 const char* new_header; | 1518 const char* new_header; |
| 1519 const char* expected_headers; | 1519 const char* expected_headers; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1538 "HTTP/1.1 200 OK\n" | 1538 "HTTP/1.1 200 OK\n" |
| 1539 "connection: keep-alive\n" | 1539 "connection: keep-alive\n" |
| 1540 "Cache-control: max-age=10000\n" | 1540 "Cache-control: max-age=10000\n" |
| 1541 "Content-Length: 450\n" | 1541 "Content-Length: 450\n" |
| 1542 }, | 1542 }, |
| 1543 }; | 1543 }; |
| 1544 | 1544 |
| 1545 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1545 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1546 string orig_headers(tests[i].orig_headers); | 1546 string orig_headers(tests[i].orig_headers); |
| 1547 HeadersToRaw(&orig_headers); | 1547 HeadersToRaw(&orig_headers); |
| 1548 scoped_refptr<HttpResponseHeaders> parsed = | 1548 scoped_refptr<HttpResponseHeaders> parsed( |
| 1549 new HttpResponseHeaders(orig_headers); | 1549 new HttpResponseHeaders(orig_headers)); |
| 1550 | 1550 |
| 1551 string new_header(tests[i].new_header); | 1551 string new_header(tests[i].new_header); |
| 1552 parsed->AddHeader(new_header); | 1552 parsed->AddHeader(new_header); |
| 1553 | 1553 |
| 1554 string resulting_headers; | 1554 string resulting_headers; |
| 1555 parsed->GetNormalizedHeaders(&resulting_headers); | 1555 parsed->GetNormalizedHeaders(&resulting_headers); |
| 1556 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); | 1556 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); |
| 1557 } | 1557 } |
| 1558 } | 1558 } |
| 1559 | 1559 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1583 | 1583 |
| 1584 "HTTP/1.1 200 OK\n" | 1584 "HTTP/1.1 200 OK\n" |
| 1585 "connection: keep-alive\n" | 1585 "connection: keep-alive\n" |
| 1586 "Cache-control: max-age=10000\n" | 1586 "Cache-control: max-age=10000\n" |
| 1587 }, | 1587 }, |
| 1588 }; | 1588 }; |
| 1589 | 1589 |
| 1590 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1590 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1591 string orig_headers(tests[i].orig_headers); | 1591 string orig_headers(tests[i].orig_headers); |
| 1592 HeadersToRaw(&orig_headers); | 1592 HeadersToRaw(&orig_headers); |
| 1593 scoped_refptr<HttpResponseHeaders> parsed = | 1593 scoped_refptr<HttpResponseHeaders> parsed( |
| 1594 new HttpResponseHeaders(orig_headers); | 1594 new HttpResponseHeaders(orig_headers)); |
| 1595 | 1595 |
| 1596 string name(tests[i].to_remove); | 1596 string name(tests[i].to_remove); |
| 1597 parsed->RemoveHeader(name); | 1597 parsed->RemoveHeader(name); |
| 1598 | 1598 |
| 1599 string resulting_headers; | 1599 string resulting_headers; |
| 1600 parsed->GetNormalizedHeaders(&resulting_headers); | 1600 parsed->GetNormalizedHeaders(&resulting_headers); |
| 1601 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); | 1601 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); |
| 1602 } | 1602 } |
| 1603 } | 1603 } |
| 1604 | 1604 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 "HTTP/1.0 304 Not Modified\n" | 1638 "HTTP/1.0 304 Not Modified\n" |
| 1639 "connection: keep-alive\n" | 1639 "connection: keep-alive\n" |
| 1640 "Content-Length: 450\n" | 1640 "Content-Length: 450\n" |
| 1641 "Cache-control: max-age=10000\n" | 1641 "Cache-control: max-age=10000\n" |
| 1642 }, | 1642 }, |
| 1643 }; | 1643 }; |
| 1644 | 1644 |
| 1645 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1645 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1646 string orig_headers(tests[i].orig_headers); | 1646 string orig_headers(tests[i].orig_headers); |
| 1647 HeadersToRaw(&orig_headers); | 1647 HeadersToRaw(&orig_headers); |
| 1648 scoped_refptr<HttpResponseHeaders> parsed = | 1648 scoped_refptr<HttpResponseHeaders> parsed( |
| 1649 new HttpResponseHeaders(orig_headers); | 1649 new HttpResponseHeaders(orig_headers)); |
| 1650 | 1650 |
| 1651 string name(tests[i].new_status); | 1651 string name(tests[i].new_status); |
| 1652 parsed->ReplaceStatusLine(name); | 1652 parsed->ReplaceStatusLine(name); |
| 1653 | 1653 |
| 1654 string resulting_headers; | 1654 string resulting_headers; |
| 1655 parsed->GetNormalizedHeaders(&resulting_headers); | 1655 parsed->GetNormalizedHeaders(&resulting_headers); |
| 1656 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); | 1656 EXPECT_EQ(string(tests[i].expected_headers), resulting_headers); |
| 1657 } | 1657 } |
| 1658 } | 1658 } |
| OLD | NEW |