OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_stream_request.h" | 5 #include "net/http/http_stream_request.h" |
6 | 6 |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 const HttpResponseInfo& response, | 199 const HttpResponseInfo& response, |
200 HttpAuthController* auth_controller) { | 200 HttpAuthController* auth_controller) { |
201 delegate_->OnNeedsProxyAuth(response, auth_controller); | 201 delegate_->OnNeedsProxyAuth(response, auth_controller); |
202 } | 202 } |
203 | 203 |
204 void HttpStreamRequest::OnNeedsClientAuthCallback( | 204 void HttpStreamRequest::OnNeedsClientAuthCallback( |
205 SSLCertRequestInfo* cert_info) { | 205 SSLCertRequestInfo* cert_info) { |
206 delegate_->OnNeedsClientAuth(cert_info); | 206 delegate_->OnNeedsClientAuth(cert_info); |
207 } | 207 } |
208 | 208 |
| 209 void HttpStreamRequest::OnHttpsProxyTunnelResponseCallback( |
| 210 const HttpResponseInfo& response_info, |
| 211 HttpStream* stream) { |
| 212 delegate_->OnHttpsProxyTunnelResponse(response_info, stream); |
| 213 } |
| 214 |
209 void HttpStreamRequest::OnPreconnectsComplete(int result) { | 215 void HttpStreamRequest::OnPreconnectsComplete(int result) { |
210 preconnect_delegate_->OnPreconnectsComplete(this, result); | 216 preconnect_delegate_->OnPreconnectsComplete(this, result); |
211 } | 217 } |
212 | 218 |
213 void HttpStreamRequest::OnIOComplete(int result) { | 219 void HttpStreamRequest::OnIOComplete(int result) { |
214 RunLoop(result); | 220 RunLoop(result); |
215 } | 221 } |
216 | 222 |
217 int HttpStreamRequest::RunLoop(int result) { | 223 int HttpStreamRequest::RunLoop(int result) { |
218 result = DoLoop(result); | 224 result = DoLoop(result); |
(...skipping 27 matching lines...) Expand all Loading... |
246 switch (result) { | 252 switch (result) { |
247 case ERR_PROXY_AUTH_REQUESTED: | 253 case ERR_PROXY_AUTH_REQUESTED: |
248 { | 254 { |
249 DCHECK(connection_.get()); | 255 DCHECK(connection_.get()); |
250 DCHECK(connection_->socket()); | 256 DCHECK(connection_->socket()); |
251 DCHECK(establishing_tunnel_); | 257 DCHECK(establishing_tunnel_); |
252 | 258 |
253 HttpProxyClientSocket* http_proxy_socket = | 259 HttpProxyClientSocket* http_proxy_socket = |
254 static_cast<HttpProxyClientSocket*>(connection_->socket()); | 260 static_cast<HttpProxyClientSocket*>(connection_->socket()); |
255 const HttpResponseInfo* tunnel_auth_response = | 261 const HttpResponseInfo* tunnel_auth_response = |
256 http_proxy_socket->GetResponseInfo(); | 262 http_proxy_socket->GetConnectResponseInfo(); |
257 | 263 |
258 next_state_ = STATE_WAITING_USER_ACTION; | 264 next_state_ = STATE_WAITING_USER_ACTION; |
259 MessageLoop::current()->PostTask( | 265 MessageLoop::current()->PostTask( |
260 FROM_HERE, | 266 FROM_HERE, |
261 method_factory_.NewRunnableMethod( | 267 method_factory_.NewRunnableMethod( |
262 &HttpStreamRequest::OnNeedsProxyAuthCallback, | 268 &HttpStreamRequest::OnNeedsProxyAuthCallback, |
263 *tunnel_auth_response, | 269 *tunnel_auth_response, |
264 http_proxy_socket->auth_controller())); | 270 http_proxy_socket->auth_controller())); |
265 } | 271 } |
266 return ERR_IO_PENDING; | 272 return ERR_IO_PENDING; |
267 | 273 |
268 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: | 274 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: |
269 MessageLoop::current()->PostTask( | 275 MessageLoop::current()->PostTask( |
270 FROM_HERE, | 276 FROM_HERE, |
271 method_factory_.NewRunnableMethod( | 277 method_factory_.NewRunnableMethod( |
272 &HttpStreamRequest::OnNeedsClientAuthCallback, | 278 &HttpStreamRequest::OnNeedsClientAuthCallback, |
273 connection_->ssl_error_response_info().cert_request_info)); | 279 connection_->ssl_error_response_info().cert_request_info)); |
274 return ERR_IO_PENDING; | 280 return ERR_IO_PENDING; |
275 | 281 |
| 282 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE: |
| 283 { |
| 284 DCHECK(connection_.get()); |
| 285 DCHECK(connection_->socket()); |
| 286 DCHECK(establishing_tunnel_); |
| 287 |
| 288 ProxyClientSocket* proxy_socket = |
| 289 static_cast<ProxyClientSocket*>(connection_->socket()); |
| 290 MessageLoop::current()->PostTask( |
| 291 FROM_HERE, |
| 292 method_factory_.NewRunnableMethod( |
| 293 &HttpStreamRequest::OnHttpsProxyTunnelResponseCallback, |
| 294 *proxy_socket->GetConnectResponseInfo(), |
| 295 proxy_socket->CreateConnectResponseStream())); |
| 296 return ERR_IO_PENDING; |
| 297 } |
| 298 |
276 case OK: | 299 case OK: |
277 next_state_ = STATE_DONE; | 300 next_state_ = STATE_DONE; |
278 MessageLoop::current()->PostTask( | 301 MessageLoop::current()->PostTask( |
279 FROM_HERE, | 302 FROM_HERE, |
280 method_factory_.NewRunnableMethod( | 303 method_factory_.NewRunnableMethod( |
281 &HttpStreamRequest::OnStreamReadyCallback)); | 304 &HttpStreamRequest::OnStreamReadyCallback)); |
282 return ERR_IO_PENDING; | 305 return ERR_IO_PENDING; |
283 | 306 |
284 default: | 307 default: |
285 MessageLoop::current()->PostTask( | 308 MessageLoop::current()->PostTask( |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 if (proxy_socket->using_spdy()) { | 678 if (proxy_socket->using_spdy()) { |
656 was_npn_negotiated_ = true; | 679 was_npn_negotiated_ = true; |
657 SwitchToSpdyMode(); | 680 SwitchToSpdyMode(); |
658 } | 681 } |
659 } | 682 } |
660 | 683 |
661 // We may be using spdy without SSL | 684 // We may be using spdy without SSL |
662 if (!force_spdy_over_ssl_ && force_spdy_always_) | 685 if (!force_spdy_over_ssl_ && force_spdy_always_) |
663 SwitchToSpdyMode(); | 686 SwitchToSpdyMode(); |
664 | 687 |
665 if (result == ERR_PROXY_AUTH_REQUESTED) { | 688 if (result == ERR_PROXY_AUTH_REQUESTED || |
| 689 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
666 DCHECK(!ssl_started); | 690 DCHECK(!ssl_started); |
667 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an | 691 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an |
668 // SSL socket, but there was an error before that could happen. This | 692 // SSL socket, but there was an error before that could happen. This |
669 // puts the in progress HttpProxy socket into |connection_| in order to | 693 // puts the in progress HttpProxy socket into |connection_| in order to |
670 // complete the auth. The tunnel restart code is careful to remove it | 694 // complete the auth (or read the response body). The tunnel restart code |
671 // before returning control to the rest of this class. | 695 // is careful to remove it before returning control to the rest of this |
| 696 // class. |
672 connection_.reset(connection_->release_pending_http_proxy_connection()); | 697 connection_.reset(connection_->release_pending_http_proxy_connection()); |
673 return result; | 698 return result; |
674 } | 699 } |
675 | 700 |
676 if ((!ssl_started && result < 0 && | 701 if ((!ssl_started && result < 0 && |
677 alternate_protocol_mode_ == kUsingAlternateProtocol) || | 702 alternate_protocol_mode_ == kUsingAlternateProtocol) || |
678 result == ERR_NPN_NEGOTIATION_FAILED) { | 703 result == ERR_NPN_NEGOTIATION_FAILED) { |
679 // Mark the alternate protocol as broken and fallback. | 704 // Mark the alternate protocol as broken and fallback. |
680 MarkBrokenAlternateProtocolAndFallback(); | 705 MarkBrokenAlternateProtocolAndFallback(); |
681 return OK; | 706 return OK; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 // this socket. Is there a race for two SPDY requests? We really | 762 // this socket. Is there a race for two SPDY requests? We really |
738 // need to plumb this through to the connect level. | 763 // need to plumb this through to the connect level. |
739 if (connection_->socket() && !connection_->is_reused()) | 764 if (connection_->socket() && !connection_->is_reused()) |
740 SetSocketMotivation(); | 765 SetSocketMotivation(); |
741 | 766 |
742 const ProxyServer& proxy_server = proxy_info()->proxy_server(); | 767 const ProxyServer& proxy_server = proxy_info()->proxy_server(); |
743 | 768 |
744 if (!using_spdy_) { | 769 if (!using_spdy_) { |
745 bool using_proxy = (proxy_info()->is_http() || proxy_info()->is_https()) && | 770 bool using_proxy = (proxy_info()->is_http() || proxy_info()->is_https()) && |
746 request_info().url.SchemeIs("http"); | 771 request_info().url.SchemeIs("http"); |
747 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); | 772 stream_.reset(new HttpBasicStream(connection_.release(), NULL, |
| 773 using_proxy)); |
748 return OK; | 774 return OK; |
749 } | 775 } |
750 | 776 |
751 CHECK(!stream_.get()); | 777 CHECK(!stream_.get()); |
752 | 778 |
753 bool direct = true; | 779 bool direct = true; |
754 SpdySessionPool* spdy_pool = session_->spdy_session_pool(); | 780 SpdySessionPool* spdy_pool = session_->spdy_session_pool(); |
755 scoped_refptr<SpdySession> spdy_session; | 781 scoped_refptr<SpdySession> spdy_session; |
756 | 782 |
757 HostPortProxyPair pair(endpoint_, proxy_server); | 783 HostPortProxyPair pair(endpoint_, proxy_server); |
(...skipping 27 matching lines...) Expand all Loading... |
785 int error = spdy_pool->GetSpdySessionFromSocket( | 811 int error = spdy_pool->GetSpdySessionFromSocket( |
786 pair, session_->mutable_spdy_settings(), connection_.release(), | 812 pair, session_->mutable_spdy_settings(), connection_.release(), |
787 net_log_, spdy_certificate_error_, &spdy_session, using_ssl_); | 813 net_log_, spdy_certificate_error_, &spdy_session, using_ssl_); |
788 if (error != OK) | 814 if (error != OK) |
789 return error; | 815 return error; |
790 } | 816 } |
791 | 817 |
792 if (spdy_session->IsClosed()) | 818 if (spdy_session->IsClosed()) |
793 return ERR_CONNECTION_CLOSED; | 819 return ERR_CONNECTION_CLOSED; |
794 | 820 |
795 bool useRelativeUrl = direct || request_info().url.SchemeIs("https"); | 821 bool use_relative_url = direct || request_info().url.SchemeIs("https"); |
796 stream_.reset(new SpdyHttpStream(spdy_session, useRelativeUrl)); | 822 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); |
797 return OK; | 823 return OK; |
798 } | 824 } |
799 | 825 |
800 int HttpStreamRequest::DoCreateStreamComplete(int result) { | 826 int HttpStreamRequest::DoCreateStreamComplete(int result) { |
801 if (result < 0) | 827 if (result < 0) |
802 return result; | 828 return result; |
803 | 829 |
804 next_state_ = STATE_NONE; | 830 next_state_ = STATE_NONE; |
805 return OK; | 831 return OK; |
806 } | 832 } |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 base::TimeDelta::FromMinutes(6), | 1083 base::TimeDelta::FromMinutes(6), |
1058 100); | 1084 100); |
1059 break; | 1085 break; |
1060 default: | 1086 default: |
1061 NOTREACHED(); | 1087 NOTREACHED(); |
1062 break; | 1088 break; |
1063 } | 1089 } |
1064 } | 1090 } |
1065 | 1091 |
1066 } // namespace net | 1092 } // namespace net |
OLD | NEW |