OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 OverrideResponseAsRedirect(request.get(), original_response_headers.get(), | 346 OverrideResponseAsRedirect(request.get(), original_response_headers.get(), |
347 &override_response_headers); | 347 &override_response_headers); |
348 int expected_flags = net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY; | 348 int expected_flags = net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY; |
349 EXPECT_EQ(expected_flags, request->load_flags()); | 349 EXPECT_EQ(expected_flags, request->load_flags()); |
350 std::string override_headers; | 350 std::string override_headers; |
351 override_response_headers->GetNormalizedHeaders(&override_headers); | 351 override_response_headers->GetNormalizedHeaders(&override_headers); |
352 EXPECT_EQ(std::string(tests[i].expected_headers), override_headers); | 352 EXPECT_EQ(std::string(tests[i].expected_headers), override_headers); |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
| 356 // Tests that the response is correctly overwritten as a redirect with CORS |
| 357 // headers when an Origin header is provided in the initial request. |
| 358 TEST_F(DataReductionProxyProtocolTest, OverrideResponseAsRedirectCORS) { |
| 359 net::TestURLRequestContext context; |
| 360 const struct { |
| 361 const char* headers; |
| 362 const char* expected_headers; |
| 363 } tests[] = { |
| 364 { "HTTP/1.1 200 0K\n" |
| 365 "Chrome-Proxy: block=1\n" |
| 366 "Via: 1.1 Chrome-Compression-Proxy\n", |
| 367 |
| 368 "HTTP/1.1 302 Found\n" |
| 369 "Chrome-Proxy: block=1\n" |
| 370 "Via: 1.1 Chrome-Compression-Proxy\n" |
| 371 "Location: http://www.google.com/\n" |
| 372 "Access-Control-Allow-Origin: http://www.else.com\n" |
| 373 "Access-Control-Allow-Credentials: true\n" |
| 374 }, |
| 375 }; |
| 376 |
| 377 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 378 std::string headers(tests[i].headers); |
| 379 HeadersToRaw(&headers); |
| 380 scoped_refptr<HttpResponseHeaders> original_response_headers( |
| 381 new HttpResponseHeaders(headers)); |
| 382 scoped_refptr<HttpResponseHeaders> override_response_headers; |
| 383 TestDelegate test_delegate; |
| 384 scoped_ptr<net::URLRequest> request( |
| 385 context.CreateRequest(GURL("http://www.google.com/"), |
| 386 net::DEFAULT_PRIORITY, |
| 387 NULL, |
| 388 NULL)); |
| 389 request->SetExtraRequestHeaderByName("Origin", "http://www.else.com", true); |
| 390 OverrideResponseAsRedirect(request.get(), original_response_headers.get(), |
| 391 &override_response_headers); |
| 392 int expected_flags = net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY; |
| 393 EXPECT_EQ(expected_flags, request->load_flags()); |
| 394 std::string override_headers; |
| 395 override_response_headers->GetNormalizedHeaders(&override_headers); |
| 396 EXPECT_EQ(std::string(tests[i].expected_headers), override_headers); |
| 397 } |
| 398 } |
| 399 |
356 | 400 |
357 // After each test, the proxy retry info will contain zero, one, or two of the | 401 // After each test, the proxy retry info will contain zero, one, or two of the |
358 // data reduction proxies depending on whether no bypass was indicated by the | 402 // data reduction proxies depending on whether no bypass was indicated by the |
359 // initial response, a single proxy bypass was indicated, or a double bypass | 403 // initial response, a single proxy bypass was indicated, or a double bypass |
360 // was indicated. In both the single and double bypass cases, if the request | 404 // was indicated. In both the single and double bypass cases, if the request |
361 // was idempotent, it will be retried over a direct connection. | 405 // was idempotent, it will be retried over a direct connection. |
362 TEST_F(DataReductionProxyProtocolTest, BypassLogic) { | 406 TEST_F(DataReductionProxyProtocolTest, BypassLogic) { |
363 const struct { | 407 const struct { |
364 const char* method; | 408 const char* method; |
365 const char* first_response; | 409 const char* first_response; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 &other_proxy_info); | 947 &other_proxy_info); |
904 EXPECT_FALSE(other_proxy_info.is_direct()); | 948 EXPECT_FALSE(other_proxy_info.is_direct()); |
905 | 949 |
906 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, | 950 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
907 empty_proxy_retry_info, &test_params, | 951 empty_proxy_retry_info, &test_params, |
908 &data_reduction_proxy_info); | 952 &data_reduction_proxy_info); |
909 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); | 953 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); |
910 } | 954 } |
911 | 955 |
912 } // namespace data_reduction_proxy | 956 } // namespace data_reduction_proxy |
OLD | NEW |