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

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

Issue 298883011: Record errors that trigger a data reduction proxy bypass (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed more comments from mef Created 6 years, 6 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_network_layer.h" 5 #include "net/http/http_network_layer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "net/base/net_log.h" 9 #include "net/base/net_log.h"
10 #include "net/cert/mock_cert_verifier.h" 10 #include "net/cert/mock_cert_verifier.h"
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 "PROXY " + bad_proxy)); 469 "PROXY " + bad_proxy));
470 TestProxyFallbackFail(1u, bad_proxy, ""); 470 TestProxyFallbackFail(1u, bad_proxy, "");
471 } 471 }
472 472
473 TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassFixed) { 473 TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassFixed) {
474 std::string bad_proxy = GetDataReductionProxy(); 474 std::string bad_proxy = GetDataReductionProxy();
475 ConfigureTestDependencies(ProxyService::CreateFixed(bad_proxy)); 475 ConfigureTestDependencies(ProxyService::CreateFixed(bad_proxy));
476 TestProxyFallbackFail(1u, bad_proxy, ""); 476 TestProxyFallbackFail(1u, bad_proxy, "");
477 } 477 }
478 478
479 TEST_F(HttpNetworkLayerTest, ServerFallbackOn5xxError) { 479 TEST_F(HttpNetworkLayerTest, ServerFallbackOn4xxAnd5xxErrors) {
480 // Verify that "500 Internal Server Error", "502 Bad Gateway", and 480 // Verify that "500 Internal Server Error", "502 Bad Gateway", and
481 // "503 Service Unavailable" via the data reduction proxy induce proxy 481 // "503 Service Unavailable" via the data reduction proxy induce proxy
482 // fallback to a second proxy, if configured. 482 // fallback to a second proxy, if configured.
483 483
484 // Verify that 4xx responses bypass both data reduction proxies, when
485 // the proxy originates them.
486
484 // To configure this test, we need to wire up a custom proxy service to use 487 // To configure this test, we need to wire up a custom proxy service to use
485 // a pair of proxies. We'll induce fallback via the first and return 488 // a pair or triplet of proxies. We'll induce fallback via the first and
486 // the expected data via the second. 489 // return the expected data via the second, or third if the first two are
490 // both bypassed.
487 std::string data_reduction_proxy( 491 std::string data_reduction_proxy(
488 HostPortPair::FromURL(GURL(SPDY_PROXY_AUTH_ORIGIN)).ToString()); 492 HostPortPair::FromURL(GURL(SPDY_PROXY_AUTH_ORIGIN)).ToString());
489 std::string pac_string = base::StringPrintf( 493 std::string data_reduction_proxy_fallback;
490 "PROXY %s; PROXY good:8080", data_reduction_proxy.data()); 494 size_t data_reduction_proxy_count = 1u;
495 #if defined(DATA_REDUCTION_FALLBACK_HOST)
496 data_reduction_proxy_fallback =
497 HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString();
498 data_reduction_proxy_count = 2u;
499 #endif
491 500
492 std::string headers[] = { 501
493 "HTTP/1.1 500 Internal Server Error\r\n\r\n", 502 const struct {
494 "HTTP/1.1 502 Bad Gateway\r\n\r\n", 503 const char* headers;
495 "HTTP/1.1 503 Service Unavailable\r\n\r\n" 504 size_t expected_proxies_on_retry_list;
505 } tests[] = {
506 { "HTTP/1.1 500 Internal Server Error\r\n\r\n", 1u },
507 { "HTTP/1.1 502 Bad Gateway\r\n\r\n", 1u },
508 { "HTTP/1.1 503 Service Unavailable\r\n\r\n", 1u },
509 { "HTTP/1.1 414 Request-URI Too Long\r\nServer: GFE/2.0\r\n\r\n",
510 data_reduction_proxy_count },
511 { "HTTP/1.1 414 Request-URI Too Long\r\n\r\n", 1u}
496 }; 512 };
497 513
498 for (size_t i = 0; i < arraysize(headers); ++i) { 514 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
515 std::string pac_string;
516 if (data_reduction_proxy_count == 1u) {
517 pac_string = base::StringPrintf(
518 "PROXY %s; PROXY good:8080", data_reduction_proxy.data());
519 } else {
520 pac_string = base::StringPrintf(
521 "PROXY %s; PROXY %s; PROXY good:8080", data_reduction_proxy.data(),
522 data_reduction_proxy_fallback.data());
523 }
499 ConfigureTestDependencies( 524 ConfigureTestDependencies(
500 ProxyService::CreateFixedFromPacResult(pac_string)); 525 ProxyService::CreateFixedFromPacResult(pac_string));
501 526
502 MockRead data_reads[] = { 527 MockRead data_reads[] = {
503 MockRead(headers[i].c_str()), 528 MockRead(tests[i].headers),
504 MockRead("Bypass message"), 529 MockRead("Bypass message"),
505 MockRead(SYNCHRONOUS, OK), 530 MockRead(SYNCHRONOUS, OK),
506 }; 531 };
507 532
508 MockWrite data_writes[] = { 533 MockWrite data_writes[] = {
509 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 534 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
510 "Host: www.google.com\r\n" 535 "Host: www.google.com\r\n"
511 "Proxy-Connection: keep-alive\r\n\r\n"), 536 "Proxy-Connection: keep-alive\r\n\r\n"),
512 }; 537 };
513 538
514 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), 539 StaticSocketDataProvider data1(data_reads, arraysize(data_reads),
515 data_writes, arraysize(data_writes)); 540 data_writes, arraysize(data_writes));
516 mock_socket_factory_.AddSocketDataProvider(&data1); 541 mock_socket_factory_.AddSocketDataProvider(&data1);
517 542
518 // Second data provider returns the expected content. 543 // Second data provider returns the expected content.
519 MockRead data_reads2[] = { 544 MockRead data_reads2[] = {
520 MockRead("HTTP/1.0 200 OK\r\n" 545 MockRead("HTTP/1.0 200 OK\r\n"
521 "Server: not-proxy\r\n\r\n"), 546 "Server: good-proxy\r\n"
547 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"),
522 MockRead("content"), 548 MockRead("content"),
523 MockRead(SYNCHRONOUS, OK), 549 MockRead(SYNCHRONOUS, OK),
524 }; 550 };
525 MockWrite data_writes2[] = { 551 MockWrite data_writes2[] = {
526 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 552 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
527 "Host: www.google.com\r\n" 553 "Host: www.google.com\r\n"
528 "Proxy-Connection: keep-alive\r\n\r\n"), 554 "Proxy-Connection: keep-alive\r\n\r\n"),
529 }; 555 };
530 556
531 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), 557 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
(...skipping 18 matching lines...) Expand all
550 576
551 std::string contents; 577 std::string contents;
552 rv = ReadTransaction(trans.get(), &contents); 578 rv = ReadTransaction(trans.get(), &contents);
553 EXPECT_EQ(OK, rv); 579 EXPECT_EQ(OK, rv);
554 580
555 // We should obtain content from the second socket provider write 581 // We should obtain content from the second socket provider write
556 // corresponding to the fallback proxy. 582 // corresponding to the fallback proxy.
557 EXPECT_EQ("content", contents); 583 EXPECT_EQ("content", contents);
558 // We also have a server header here that isn't set by the proxy. 584 // We also have a server header here that isn't set by the proxy.
559 EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue( 585 EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue(
560 "server", "not-proxy")); 586 "server", "good-proxy"));
561 // We should also observe the data reduction proxy in the retry list. 587 // We should also observe the data reduction proxy in the retry list.
562 ASSERT_EQ(1u, proxy_service_->proxy_retry_info().size()); 588 ASSERT_EQ(tests[i].expected_proxies_on_retry_list,
563 EXPECT_EQ(data_reduction_proxy, 589 proxy_service_->proxy_retry_info().size());
564 (*proxy_service_->proxy_retry_info().begin()).first); 590 EXPECT_EQ(1u,
591 proxy_service_->proxy_retry_info().count(data_reduction_proxy));
592 if (tests[i].expected_proxies_on_retry_list == 2u)
593 EXPECT_EQ(1u,
594 proxy_service_->proxy_retry_info().count(
595 data_reduction_proxy_fallback));
565 } 596 }
566 } 597 }
567 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) 598 #endif // defined(SPDY_PROXY_AUTH_ORIGIN)
568 599
569 TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) { 600 TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) {
570 // Verify that a Chrome-Proxy header is ignored when returned from a directly 601 // Verify that a Chrome-Proxy header is ignored when returned from a directly
571 // connected origin server. 602 // connected origin server.
572 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); 603 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT"));
573 604
574 MockRead data_reads[] = { 605 MockRead data_reads[] = {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 MockRead("HTTP/1.1 200 OK\r\n" 695 MockRead("HTTP/1.1 200 OK\r\n"
665 "Connection: keep-alive\r\n\r\n"), 696 "Connection: keep-alive\r\n\r\n"),
666 MockRead("Bypass message"), 697 MockRead("Bypass message"),
667 MockRead(SYNCHRONOUS, OK), 698 MockRead(SYNCHRONOUS, OK),
668 }; 699 };
669 700
670 TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads, 701 TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads,
671 arraysize(data_reads), 1u); 702 arraysize(data_reads), 1u);
672 } 703 }
673 704
705 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith4xxFromOrigin) {
706 // Verify that Chrome will not be induced to bypass the data reduction proxy
707 // when the data reduction proxy via header is present on a 4xx.
708 std::string chrome_proxy = GetDataReductionProxy();
709 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult(
710 "PROXY " + chrome_proxy + "; PROXY good:8080"));
711
712 MockRead data_reads[] = {
713 MockRead("HTTP/1.1 414 Request-URI Too Long\r\n"
714 "Connection: keep-alive\r\n"
715 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"),
716 MockRead(SYNCHRONOUS, OK),
717 };
718
719 TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(),
720 data_reads, arraysize(data_reads),
721 "GET", std::string(), false, 0);
722 }
723
674 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) { 724 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) {
675 // Verify that Chrome will not be induced to bypass the data reduction proxy 725 // Verify that Chrome will not be induced to bypass the data reduction proxy
676 // when the data reduction proxy via header is absent on a 304. 726 // when the data reduction proxy via header is absent on a 304.
677 std::string chrome_proxy = GetDataReductionProxy(); 727 std::string chrome_proxy = GetDataReductionProxy();
678 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 728 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult(
679 "PROXY " + chrome_proxy + "; PROXY good:8080")); 729 "PROXY " + chrome_proxy + "; PROXY good:8080"));
680 730
681 MockRead data_reads[] = { 731 MockRead data_reads[] = {
682 MockRead("HTTP/1.1 304 Not Modified\r\n" 732 MockRead("HTTP/1.1 304 Not Modified\r\n"
683 "Connection: keep-alive\r\n\r\n"), 733 "Connection: keep-alive\r\n\r\n"),
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv)); 875 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv));
826 876
827 // If the response info is null, that means that any consumer won't 877 // If the response info is null, that means that any consumer won't
828 // see the network accessed bit set. 878 // see the network accessed bit set.
829 EXPECT_EQ(NULL, trans->GetResponseInfo()); 879 EXPECT_EQ(NULL, trans->GetResponseInfo());
830 } 880 }
831 881
832 } // namespace 882 } // namespace
833 883
834 } // namespace net 884 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698