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

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

Issue 2643023003: Speed up sanitizing headers received from HTTP proxies. (Closed)
Patch Set: Fix Created 3 years, 11 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
OLDNEW
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 "net/http/http_response_headers.h" 5 #include "net/http/http_response_headers.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iostream> 10 #include <iostream>
11 #include <limits> 11 #include <limits>
12 #include <memory> 12 #include <memory>
13 #include <unordered_set>
13 14
14 #include "base/pickle.h" 15 #include "base/pickle.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "net/http/http_byte_range.h" 18 #include "net/http/http_byte_range.h"
18 #include "net/log/net_log_capture_mode.h" 19 #include "net/log/net_log_capture_mode.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace net { 22 namespace net {
22 23
(...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 "HTTP/1.1 200 OK\n" 1757 "HTTP/1.1 200 OK\n"
1757 "connection: keep-alive\n" 1758 "connection: keep-alive\n"
1758 "Cache-control: max-age=10000\n" 1759 "Cache-control: max-age=10000\n"
1759 }, 1760 },
1760 }; 1761 };
1761 1762
1762 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, 1763 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders,
1763 RemoveHeaderTest, 1764 RemoveHeaderTest,
1764 testing::ValuesIn(remove_header_tests)); 1765 testing::ValuesIn(remove_header_tests));
1765 1766
1767 struct RemoveHeadersTestData {
1768 const char* orig_headers;
1769 const char* to_remove[2];
1770 const char* expected_headers;
1771 };
1772
1773 class RemoveHeadersTest
1774 : public HttpResponseHeadersTest,
1775 public ::testing::WithParamInterface<RemoveHeadersTestData> {};
1776
1777 TEST_P(RemoveHeadersTest, RemoveHeaders) {
1778 const RemoveHeadersTestData test = GetParam();
1779
1780 std::string orig_headers(test.orig_headers);
1781 HeadersToRaw(&orig_headers);
1782 scoped_refptr<HttpResponseHeaders> parsed(
1783 new HttpResponseHeaders(orig_headers));
1784
1785 std::unordered_set<std::string> to_remove;
1786 for (const auto& header : test.to_remove) {
1787 if (header)
1788 to_remove.insert(header);
1789 }
1790 parsed->RemoveHeaders(to_remove);
1791
1792 std::string resulting_headers;
1793 parsed->GetNormalizedHeaders(&resulting_headers);
1794 EXPECT_EQ(std::string(test.expected_headers), resulting_headers);
1795 }
1796
1797 const RemoveHeadersTestData remove_headers_tests[] = {
1798 {"HTTP/1.1 200 OK\n"
1799 "connection: keep-alive\n"
1800 "Cache-control: max-age=10000\n"
1801 "Content-Length: 450\n",
1802
1803 {"Content-Length", "CACHE-control"},
1804
1805 "HTTP/1.1 200 OK\n"
1806 "connection: keep-alive\n"},
1807
1808 {"HTTP/1.1 200 OK\n"
1809 "connection: keep-alive\n"
1810 "Content-Length: 450\n",
1811
1812 {"foo", "bar"},
1813
1814 "HTTP/1.1 200 OK\n"
1815 "connection: keep-alive\n"
1816 "Content-Length: 450\n"},
1817
1818 {"HTTP/1.1 404 Kinda not OK\n"
1819 "connection: keep-alive \n",
1820
1821 {},
1822
1823 "HTTP/1.1 404 Kinda not OK\n"
1824 "connection: keep-alive\n"},
1825 };
1826
1827 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders,
1828 RemoveHeadersTest,
1829 testing::ValuesIn(remove_headers_tests));
1830
1766 struct RemoveIndividualHeaderTestData { 1831 struct RemoveIndividualHeaderTestData {
1767 const char* orig_headers; 1832 const char* orig_headers;
1768 const char* to_remove_name; 1833 const char* to_remove_name;
1769 const char* to_remove_value; 1834 const char* to_remove_value;
1770 const char* expected_headers; 1835 const char* expected_headers;
1771 }; 1836 };
1772 1837
1773 class RemoveIndividualHeaderTest 1838 class RemoveIndividualHeaderTest
1774 : public HttpResponseHeadersTest, 1839 : public HttpResponseHeadersTest,
1775 public ::testing::WithParamInterface<RemoveIndividualHeaderTestData> { 1840 public ::testing::WithParamInterface<RemoveIndividualHeaderTestData> {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 TEST_F(HttpResponseHeadersCacheControlTest, 2196 TEST_F(HttpResponseHeadersCacheControlTest,
2132 FirstStaleWhileRevalidateValueUsed) { 2197 FirstStaleWhileRevalidateValueUsed) {
2133 InitializeHeadersWithCacheControl( 2198 InitializeHeadersWithCacheControl(
2134 "stale-while-revalidate=1,stale-while-revalidate=7200"); 2199 "stale-while-revalidate=1,stale-while-revalidate=7200");
2135 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); 2200 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue());
2136 } 2201 }
2137 2202
2138 } // namespace 2203 } // namespace
2139 2204
2140 } // namespace net 2205 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698