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

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

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 total_received_bytes_ += stream_->GetTotalReceivedBytes(); 563 total_received_bytes_ += stream_->GetTotalReceivedBytes();
564 stream_.reset(stream); 564 stream_.reset(stream);
565 stream_request_.reset(); // we're done with the stream request 565 stream_request_.reset(); // we're done with the stream request
566 OnIOComplete(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); 566 OnIOComplete(ERR_HTTPS_PROXY_TUNNEL_RESPONSE);
567 } 567 }
568 568
569 bool HttpNetworkTransaction::is_https_request() const { 569 bool HttpNetworkTransaction::is_https_request() const {
570 return request_->url.SchemeIs("https"); 570 return request_->url.SchemeIs("https");
571 } 571 }
572 572
573 bool HttpNetworkTransaction::UsingHttpProxyWithoutTunnel() const {
574 return (proxy_info_.is_http() || proxy_info_.is_https()) &&
575 !(request_->url.SchemeIs("https") || request_->url.SchemeIsWSOrWSS());
576 }
577
573 void HttpNetworkTransaction::DoCallback(int rv) { 578 void HttpNetworkTransaction::DoCallback(int rv) {
574 DCHECK_NE(rv, ERR_IO_PENDING); 579 DCHECK_NE(rv, ERR_IO_PENDING);
575 DCHECK(!callback_.is_null()); 580 DCHECK(!callback_.is_null());
576 581
577 // Since Run may result in Read being called, clear user_callback_ up front. 582 // Since Run may result in Read being called, clear user_callback_ up front.
578 CompletionCallback c = callback_; 583 CompletionCallback c = callback_;
579 callback_.Reset(); 584 callback_.Reset();
580 c.Run(rv); 585 c.Run(rv);
581 } 586 }
582 587
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 net_log_); 832 net_log_);
828 } 833 }
829 834
830 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { 835 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) {
831 DCHECK_NE(ERR_IO_PENDING, rv); 836 DCHECK_NE(ERR_IO_PENDING, rv);
832 if (rv == OK) 837 if (rv == OK)
833 next_state_ = STATE_INIT_REQUEST_BODY; 838 next_state_ = STATE_INIT_REQUEST_BODY;
834 return rv; 839 return rv;
835 } 840 }
836 841
837 void HttpNetworkTransaction::BuildRequestHeaders(bool using_proxy) { 842 void HttpNetworkTransaction::BuildRequestHeaders(
843 bool using_http_proxy_without_tunnel) {
838 request_headers_.SetHeader(HttpRequestHeaders::kHost, 844 request_headers_.SetHeader(HttpRequestHeaders::kHost,
839 GetHostAndOptionalPort(request_->url)); 845 GetHostAndOptionalPort(request_->url));
840 846
841 // For compat with HTTP/1.0 servers and proxies: 847 // For compat with HTTP/1.0 servers and proxies:
842 if (using_proxy) { 848 if (using_http_proxy_without_tunnel) {
843 request_headers_.SetHeader(HttpRequestHeaders::kProxyConnection, 849 request_headers_.SetHeader(HttpRequestHeaders::kProxyConnection,
844 "keep-alive"); 850 "keep-alive");
845 } else { 851 } else {
846 request_headers_.SetHeader(HttpRequestHeaders::kConnection, "keep-alive"); 852 request_headers_.SetHeader(HttpRequestHeaders::kConnection, "keep-alive");
847 } 853 }
848 854
849 // Add a content length header? 855 // Add a content length header?
850 if (request_->upload_data_stream) { 856 if (request_->upload_data_stream) {
851 if (request_->upload_data_stream->is_chunked()) { 857 if (request_->upload_data_stream->is_chunked()) {
852 request_headers_.SetHeader( 858 request_headers_.SetHeader(
(...skipping 22 matching lines...) Expand all
875 881
876 if (ShouldApplyProxyAuth() && HaveAuth(HttpAuth::AUTH_PROXY)) 882 if (ShouldApplyProxyAuth() && HaveAuth(HttpAuth::AUTH_PROXY))
877 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader( 883 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader(
878 &request_headers_); 884 &request_headers_);
879 if (ShouldApplyServerAuth() && HaveAuth(HttpAuth::AUTH_SERVER)) 885 if (ShouldApplyServerAuth() && HaveAuth(HttpAuth::AUTH_SERVER))
880 auth_controllers_[HttpAuth::AUTH_SERVER]->AddAuthorizationHeader( 886 auth_controllers_[HttpAuth::AUTH_SERVER]->AddAuthorizationHeader(
881 &request_headers_); 887 &request_headers_);
882 888
883 request_headers_.MergeFrom(request_->extra_headers); 889 request_headers_.MergeFrom(request_->extra_headers);
884 890
885 if (using_proxy && !before_proxy_headers_sent_callback_.is_null()) 891 if (using_http_proxy_without_tunnel &&
892 !before_proxy_headers_sent_callback_.is_null())
886 before_proxy_headers_sent_callback_.Run(proxy_info_, &request_headers_); 893 before_proxy_headers_sent_callback_.Run(proxy_info_, &request_headers_);
887 894
888 response_.did_use_http_auth = 895 response_.did_use_http_auth =
889 request_headers_.HasHeader(HttpRequestHeaders::kAuthorization) || 896 request_headers_.HasHeader(HttpRequestHeaders::kAuthorization) ||
890 request_headers_.HasHeader(HttpRequestHeaders::kProxyAuthorization); 897 request_headers_.HasHeader(HttpRequestHeaders::kProxyAuthorization);
891 } 898 }
892 899
893 int HttpNetworkTransaction::DoInitRequestBody() { 900 int HttpNetworkTransaction::DoInitRequestBody() {
894 next_state_ = STATE_INIT_REQUEST_BODY_COMPLETE; 901 next_state_ = STATE_INIT_REQUEST_BODY_COMPLETE;
895 int rv = OK; 902 int rv = OK;
896 if (request_->upload_data_stream) 903 if (request_->upload_data_stream)
897 rv = request_->upload_data_stream->Init(io_callback_); 904 rv = request_->upload_data_stream->Init(io_callback_);
898 return rv; 905 return rv;
899 } 906 }
900 907
901 int HttpNetworkTransaction::DoInitRequestBodyComplete(int result) { 908 int HttpNetworkTransaction::DoInitRequestBodyComplete(int result) {
902 if (result == OK) 909 if (result == OK)
903 next_state_ = STATE_BUILD_REQUEST; 910 next_state_ = STATE_BUILD_REQUEST;
904 return result; 911 return result;
905 } 912 }
906 913
907 int HttpNetworkTransaction::DoBuildRequest() { 914 int HttpNetworkTransaction::DoBuildRequest() {
908 next_state_ = STATE_BUILD_REQUEST_COMPLETE; 915 next_state_ = STATE_BUILD_REQUEST_COMPLETE;
909 headers_valid_ = false; 916 headers_valid_ = false;
910 917
911 // This is constructed lazily (instead of within our Start method), so that 918 // This is constructed lazily (instead of within our Start method), so that
912 // we have proxy info available. 919 // we have proxy info available.
913 if (request_headers_.IsEmpty()) { 920 if (request_headers_.IsEmpty()) {
914 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && 921 bool using_http_proxy_without_tunnel = UsingHttpProxyWithoutTunnel();
915 !is_https_request(); 922 BuildRequestHeaders(using_http_proxy_without_tunnel);
916 BuildRequestHeaders(using_proxy);
917 } 923 }
918 924
919 return OK; 925 return OK;
920 } 926 }
921 927
922 int HttpNetworkTransaction::DoBuildRequestComplete(int result) { 928 int HttpNetworkTransaction::DoBuildRequestComplete(int result) {
923 if (result == OK) 929 if (result == OK)
924 next_state_ = STATE_SEND_REQUEST; 930 next_state_ = STATE_SEND_REQUEST;
925 return result; 931 return result;
926 } 932 }
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 } 1416 }
1411 1417
1412 // We need to clear request_headers_ because it contains the real request 1418 // We need to clear request_headers_ because it contains the real request
1413 // headers, but we may need to resend the CONNECT request first to recreate 1419 // headers, but we may need to resend the CONNECT request first to recreate
1414 // the SSL tunnel. 1420 // the SSL tunnel.
1415 request_headers_.Clear(); 1421 request_headers_.Clear();
1416 next_state_ = STATE_CREATE_STREAM; // Resend the request. 1422 next_state_ = STATE_CREATE_STREAM; // Resend the request.
1417 } 1423 }
1418 1424
1419 bool HttpNetworkTransaction::ShouldApplyProxyAuth() const { 1425 bool HttpNetworkTransaction::ShouldApplyProxyAuth() const {
1420 return !is_https_request() && 1426 return UsingHttpProxyWithoutTunnel();
1421 (proxy_info_.is_https() || proxy_info_.is_http());
1422 } 1427 }
1423 1428
1424 bool HttpNetworkTransaction::ShouldApplyServerAuth() const { 1429 bool HttpNetworkTransaction::ShouldApplyServerAuth() const {
1425 return !(request_->load_flags & LOAD_DO_NOT_SEND_AUTH_DATA); 1430 return !(request_->load_flags & LOAD_DO_NOT_SEND_AUTH_DATA);
1426 } 1431 }
1427 1432
1428 int HttpNetworkTransaction::HandleAuthChallenge() { 1433 int HttpNetworkTransaction::HandleAuthChallenge() {
1429 scoped_refptr<HttpResponseHeaders> headers(GetResponseHeaders()); 1434 scoped_refptr<HttpResponseHeaders> headers(GetResponseHeaders());
1430 DCHECK(headers.get()); 1435 DCHECK(headers.get());
1431 1436
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, 1530 description = base::StringPrintf("Unknown state 0x%08X (%u)", state,
1526 state); 1531 state);
1527 break; 1532 break;
1528 } 1533 }
1529 return description; 1534 return description;
1530 } 1535 }
1531 1536
1532 #undef STATE_CASE 1537 #undef STATE_CASE
1533 1538
1534 } // namespace net 1539 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698