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_proxy_client_socket.h" | 5 #include "net/http/http_proxy_client_socket.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "net/base/host_port_pair.h" | 9 #include "net/base/host_port_pair.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 void HttpProxyClientSocket::Disconnect() { | 152 void HttpProxyClientSocket::Disconnect() { |
153 transport_->socket()->Disconnect(); | 153 transport_->socket()->Disconnect(); |
154 | 154 |
155 // Reset other states to make sure they aren't mistakenly used later. | 155 // Reset other states to make sure they aren't mistakenly used later. |
156 // These are the states initialized by Connect(). | 156 // These are the states initialized by Connect(). |
157 next_state_ = STATE_NONE; | 157 next_state_ = STATE_NONE; |
158 user_callback_ = NULL; | 158 user_callback_ = NULL; |
159 } | 159 } |
160 | 160 |
161 bool HttpProxyClientSocket::IsConnected() const { | 161 bool HttpProxyClientSocket::IsConnected() const { |
162 return next_state_ == STATE_DONE && transport_->socket()->IsConnected(); | 162 return transport_->socket()->IsConnected(); |
163 } | 163 } |
164 | 164 |
165 bool HttpProxyClientSocket::IsConnectedAndIdle() const { | 165 bool HttpProxyClientSocket::IsConnectedAndIdle() const { |
166 return next_state_ == STATE_DONE | 166 return transport_->socket()->IsConnectedAndIdle(); |
167 && transport_->socket()->IsConnectedAndIdle(); | 167 } |
| 168 |
| 169 bool HttpProxyClientSocket::NeedsRestartWithAuth() const { |
| 170 return next_state_ != STATE_DONE; |
168 } | 171 } |
169 | 172 |
170 int HttpProxyClientSocket::Read(IOBuffer* buf, int buf_len, | 173 int HttpProxyClientSocket::Read(IOBuffer* buf, int buf_len, |
171 CompletionCallback* callback) { | 174 CompletionCallback* callback) { |
172 DCHECK(!user_callback_); | 175 DCHECK(!user_callback_); |
173 if (next_state_ != STATE_DONE) { | 176 if (next_state_ != STATE_DONE) { |
174 // We're trying to read the body of the response but we're still trying | 177 // We're trying to read the body of the response but we're still trying |
175 // to establish an SSL tunnel through the proxy. We can't read these | 178 // to establish an SSL tunnel through the proxy. We can't read these |
176 // bytes when establishing a tunnel because they might be controlled by | 179 // bytes when establishing a tunnel because they might be controlled by |
177 // an active network attacker. We don't worry about this for HTTP | 180 // an active network attacker. We don't worry about this for HTTP |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 next_state_ = STATE_READ_HEADERS; | 332 next_state_ = STATE_READ_HEADERS; |
330 return OK; | 333 return OK; |
331 } | 334 } |
332 | 335 |
333 int HttpProxyClientSocket::DoReadHeaders() { | 336 int HttpProxyClientSocket::DoReadHeaders() { |
334 next_state_ = STATE_READ_HEADERS_COMPLETE; | 337 next_state_ = STATE_READ_HEADERS_COMPLETE; |
335 return http_stream_->ReadResponseHeaders(&io_callback_); | 338 return http_stream_->ReadResponseHeaders(&io_callback_); |
336 } | 339 } |
337 | 340 |
338 int HttpProxyClientSocket::DoReadHeadersComplete(int result) { | 341 int HttpProxyClientSocket::DoReadHeadersComplete(int result) { |
339 if (result < 0) { | 342 if (result < 0) |
340 if (result == ERR_CONNECTION_CLOSED) | |
341 result = ERR_TUNNEL_CONNECTION_FAILED; | |
342 return result; | 343 return result; |
343 } | |
344 | 344 |
345 // Require the "HTTP/1.x" status line for SSL CONNECT. | 345 // Require the "HTTP/1.x" status line for SSL CONNECT. |
346 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) | 346 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) |
347 return ERR_TUNNEL_CONNECTION_FAILED; | 347 return ERR_TUNNEL_CONNECTION_FAILED; |
348 | 348 |
349 if (net_log_.HasListener()) { | 349 if (net_log_.HasListener()) { |
350 net_log_.AddEvent( | 350 net_log_.AddEvent( |
351 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 351 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
352 new NetLogHttpResponseParameter(response_.headers)); | 352 new NetLogHttpResponseParameter(response_.headers)); |
353 } | 353 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 411 |
412 int rv = auth_->HandleAuthChallenge(response_.headers, false, true, net_log_); | 412 int rv = auth_->HandleAuthChallenge(response_.headers, false, true, net_log_); |
413 response_.auth_challenge = auth_->auth_info(); | 413 response_.auth_challenge = auth_->auth_info(); |
414 if (rv == OK) | 414 if (rv == OK) |
415 return ERR_PROXY_AUTH_REQUESTED; | 415 return ERR_PROXY_AUTH_REQUESTED; |
416 | 416 |
417 return rv; | 417 return rv; |
418 } | 418 } |
419 | 419 |
420 } // namespace net | 420 } // namespace net |
OLD | NEW |