OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 | 1617 |
1618 std::string name(tests[i].to_remove); | 1618 std::string name(tests[i].to_remove); |
1619 parsed->RemoveHeader(name); | 1619 parsed->RemoveHeader(name); |
1620 | 1620 |
1621 std::string resulting_headers; | 1621 std::string resulting_headers; |
1622 parsed->GetNormalizedHeaders(&resulting_headers); | 1622 parsed->GetNormalizedHeaders(&resulting_headers); |
1623 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); | 1623 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); |
1624 } | 1624 } |
1625 } | 1625 } |
1626 | 1626 |
| 1627 TEST(HttpResponseHeadersTest, RemoveIndividualHeader) { |
| 1628 const struct { |
| 1629 const char* orig_headers; |
| 1630 const char* to_remove_name; |
| 1631 const char* to_remove_value; |
| 1632 const char* expected_headers; |
| 1633 } tests[] = { |
| 1634 { "HTTP/1.1 200 OK\n" |
| 1635 "connection: keep-alive\n" |
| 1636 "Cache-control: max-age=10000\n" |
| 1637 "Content-Length: 450\n", |
| 1638 |
| 1639 "Content-Length", |
| 1640 |
| 1641 "450", |
| 1642 |
| 1643 "HTTP/1.1 200 OK\n" |
| 1644 "connection: keep-alive\n" |
| 1645 "Cache-control: max-age=10000\n" |
| 1646 }, |
| 1647 { "HTTP/1.1 200 OK\n" |
| 1648 "connection: keep-alive \n" |
| 1649 "Content-Length : 450 \n" |
| 1650 "Cache-control: max-age=10000\n", |
| 1651 |
| 1652 "Content-Length", |
| 1653 |
| 1654 "450", |
| 1655 |
| 1656 "HTTP/1.1 200 OK\n" |
| 1657 "connection: keep-alive\n" |
| 1658 "Cache-control: max-age=10000\n" |
| 1659 }, |
| 1660 { "HTTP/1.1 200 OK\n" |
| 1661 "connection: keep-alive \n" |
| 1662 "Content-Length: 450\n" |
| 1663 "Cache-control: max-age=10000\n", |
| 1664 |
| 1665 "Content-Length", // Matching name. |
| 1666 |
| 1667 "999", // Mismatching value. |
| 1668 |
| 1669 "HTTP/1.1 200 OK\n" |
| 1670 "connection: keep-alive\n" |
| 1671 "Content-Length: 450\n" |
| 1672 "Cache-control: max-age=10000\n" |
| 1673 }, |
| 1674 |
| 1675 }; |
| 1676 |
| 1677 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1678 std::string orig_headers(tests[i].orig_headers); |
| 1679 HeadersToRaw(&orig_headers); |
| 1680 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 1681 new net::HttpResponseHeaders(orig_headers)); |
| 1682 |
| 1683 std::string name(tests[i].to_remove_name); |
| 1684 std::string value(tests[i].to_remove_value); |
| 1685 parsed->RemoveHeaderWithValue(name, value); |
| 1686 |
| 1687 std::string resulting_headers; |
| 1688 parsed->GetNormalizedHeaders(&resulting_headers); |
| 1689 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); |
| 1690 } |
| 1691 } |
| 1692 |
1627 TEST(HttpResponseHeadersTest, ReplaceStatus) { | 1693 TEST(HttpResponseHeadersTest, ReplaceStatus) { |
1628 const struct { | 1694 const struct { |
1629 const char* orig_headers; | 1695 const char* orig_headers; |
1630 const char* new_status; | 1696 const char* new_status; |
1631 const char* expected_headers; | 1697 const char* expected_headers; |
1632 } tests[] = { | 1698 } tests[] = { |
1633 { "HTTP/1.1 206 Partial Content\n" | 1699 { "HTTP/1.1 206 Partial Content\n" |
1634 "connection: keep-alive\n" | 1700 "connection: keep-alive\n" |
1635 "Cache-control: max-age=10000\n" | 1701 "Cache-control: max-age=10000\n" |
1636 "Content-Length: 450\n", | 1702 "Content-Length: 450\n", |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 new net::HttpResponseHeaders(orig_headers)); | 1737 new net::HttpResponseHeaders(orig_headers)); |
1672 | 1738 |
1673 std::string name(tests[i].new_status); | 1739 std::string name(tests[i].new_status); |
1674 parsed->ReplaceStatusLine(name); | 1740 parsed->ReplaceStatusLine(name); |
1675 | 1741 |
1676 std::string resulting_headers; | 1742 std::string resulting_headers; |
1677 parsed->GetNormalizedHeaders(&resulting_headers); | 1743 parsed->GetNormalizedHeaders(&resulting_headers); |
1678 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); | 1744 EXPECT_EQ(std::string(tests[i].expected_headers), resulting_headers); |
1679 } | 1745 } |
1680 } | 1746 } |
OLD | NEW |