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

Side by Side Diff: net/spdy/spdy_proxy_client_socket.cc

Issue 9316101: Revert 118950 - Allow chrome to handle 407 auth challenges to CONNECT requests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_proxy_client_socket.h ('k') | net/spdy/spdy_proxy_client_socket_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/spdy/spdy_proxy_client_socket.h" 5 #include "net/spdy/spdy_proxy_client_socket.h"
6 6
7 #include <algorithm> // min 7 #include <algorithm> // min
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "net/base/auth.h" 14 #include "net/base/auth.h"
15 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
16 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
17 #include "net/http/http_auth_cache.h"
18 #include "net/http/http_auth_handler_factory.h"
17 #include "net/http/http_net_log_params.h" 19 #include "net/http/http_net_log_params.h"
18 #include "net/http/http_proxy_utils.h" 20 #include "net/http/http_proxy_utils.h"
19 #include "net/http/http_response_headers.h" 21 #include "net/http/http_response_headers.h"
20 #include "net/spdy/spdy_http_utils.h" 22 #include "net/spdy/spdy_http_utils.h"
21 23
22 namespace net { 24 namespace net {
23 25
24 SpdyProxyClientSocket::SpdyProxyClientSocket( 26 SpdyProxyClientSocket::SpdyProxyClientSocket(
25 SpdyStream* spdy_stream, 27 SpdyStream* spdy_stream,
26 const std::string& user_agent, 28 const std::string& user_agent,
27 const HostPortPair& endpoint, 29 const HostPortPair& endpoint,
28 const GURL& url, 30 const GURL& url,
29 const HostPortPair& proxy_server, 31 const HostPortPair& proxy_server,
30 HttpAuthController* http_auth_controller) 32 HttpAuthCache* auth_cache,
33 HttpAuthHandlerFactory* auth_handler_factory)
31 : next_state_(STATE_DISCONNECTED), 34 : next_state_(STATE_DISCONNECTED),
32 spdy_stream_(spdy_stream), 35 spdy_stream_(spdy_stream),
33 endpoint_(endpoint), 36 endpoint_(endpoint),
34 auth_(http_auth_controller), 37 auth_(
38 new HttpAuthController(HttpAuth::AUTH_PROXY,
39 GURL("https://" + proxy_server.ToString()),
40 auth_cache,
41 auth_handler_factory)),
35 user_buffer_(NULL), 42 user_buffer_(NULL),
36 write_buffer_len_(0), 43 write_buffer_len_(0),
37 write_bytes_outstanding_(0), 44 write_bytes_outstanding_(0),
38 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 45 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
39 net_log_(spdy_stream->net_log()) { 46 net_log_(spdy_stream->net_log()) {
40 request_.method = "CONNECT"; 47 request_.method = "CONNECT";
41 request_.url = url; 48 request_.url = url;
42 if (!user_agent.empty()) 49 if (!user_agent.empty())
43 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 50 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
44 user_agent); 51 user_agent);
45 spdy_stream_->SetDelegate(this); 52 spdy_stream_->SetDelegate(this);
46 was_ever_used_ = spdy_stream_->WasEverUsed(); 53 was_ever_used_ = spdy_stream_->WasEverUsed();
47 } 54 }
48 55
49 SpdyProxyClientSocket::~SpdyProxyClientSocket() { 56 SpdyProxyClientSocket::~SpdyProxyClientSocket() {
50 Disconnect(); 57 Disconnect();
51 } 58 }
52 59
53 const HttpResponseInfo* SpdyProxyClientSocket::GetConnectResponseInfo() const { 60 const HttpResponseInfo* SpdyProxyClientSocket::GetConnectResponseInfo() const {
54 return response_.headers ? &response_ : NULL; 61 return response_.headers ? &response_ : NULL;
55 } 62 }
56 63
57 const
58 scoped_refptr<HttpAuthController>& SpdyProxyClientSocket::GetAuthController() {
59 return auth_;
60 }
61
62 int SpdyProxyClientSocket::RestartWithAuth(const CompletionCallback& callback) {
63 // A SPDY Stream can only handle a single request, so the underlying
64 // stream may not be reused and a new SpdyProxyClientSocket must be
65 // created (possibly on top of the same SPDY Session).
66 next_state_ = STATE_DISCONNECTED;
67 return ERR_NO_KEEP_ALIVE_ON_AUTH_RESTART;
68 }
69
70 HttpStream* SpdyProxyClientSocket::CreateConnectResponseStream() { 64 HttpStream* SpdyProxyClientSocket::CreateConnectResponseStream() {
71 DCHECK(response_stream_.get()); 65 DCHECK(response_stream_.get());
72 return response_stream_.release(); 66 return response_stream_.release();
73 } 67 }
74 68
75 // Sends a SYN_STREAM frame to the proxy with a CONNECT request 69 // Sends a SYN_STREAM frame to the proxy with a CONNECT request
76 // for the specified endpoint. Waits for the server to send back 70 // for the specified endpoint. Waits for the server to send back
77 // a SYN_REPLY frame. OK will be returned if the status is 200. 71 // a SYN_REPLY frame. OK will be returned if the status is 200.
78 // ERR_TUNNEL_CONNECTION_FAILED will be returned for any other status. 72 // ERR_TUNNEL_CONNECTION_FAILED will be returned for any other status.
79 // In any of these cases, Read() may be called to retrieve the HTTP 73 // In any of these cases, Read() may be called to retrieve the HTTP
80 // response body. Any other return values should be considered fatal. 74 // response body. Any other return values should be considered fatal.
75 // TODO(rch): handle 407 proxy auth requested correctly, perhaps
76 // by creating a new stream for the subsequent request.
81 // TODO(rch): create a more appropriate error code to disambiguate 77 // TODO(rch): create a more appropriate error code to disambiguate
82 // the HTTPS Proxy tunnel failure from an HTTP Proxy tunnel failure. 78 // the HTTPS Proxy tunnel failure from an HTTP Proxy tunnel failure.
83 int SpdyProxyClientSocket::Connect(const CompletionCallback& callback) { 79 int SpdyProxyClientSocket::Connect(const CompletionCallback& callback) {
84 DCHECK(read_callback_.is_null()); 80 DCHECK(read_callback_.is_null());
85 if (next_state_ == STATE_OPEN) 81 if (next_state_ == STATE_OPEN)
86 return OK; 82 return OK;
87 83
88 DCHECK_EQ(STATE_DISCONNECTED, next_state_); 84 DCHECK_EQ(STATE_DISCONNECTED, next_state_);
89 next_state_ = STATE_GENERATE_AUTH_TOKEN; 85 next_state_ = STATE_GENERATE_AUTH_TOKEN;
90 86
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 next_state_ = STATE_OPEN; 372 next_state_ = STATE_OPEN;
377 if (net_log_.IsLoggingAllEvents()) { 373 if (net_log_.IsLoggingAllEvents()) {
378 net_log_.AddEvent( 374 net_log_.AddEvent(
379 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 375 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
380 make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers))); 376 make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers)));
381 } 377 }
382 378
383 if (response_.headers->response_code() == 200) { 379 if (response_.headers->response_code() == 200) {
384 return OK; 380 return OK;
385 } else if (response_.headers->response_code() == 407) { 381 } else if (response_.headers->response_code() == 407) {
386 int rv = HandleAuthChallenge(auth_, &response_, net_log_); 382 return ERR_TUNNEL_CONNECTION_FAILED;
387 if (rv != ERR_PROXY_AUTH_REQUESTED) {
388 return rv;
389 }
390 // SPDY only supports basic and digest auth
391 if (!auth_->auth_info() ||
392 (auth_->auth_info()->scheme != "basic" &&
393 auth_->auth_info()->scheme != "digest")) {
394 return ERR_PROXY_AUTH_UNSUPPORTED;
395 }
396 return ERR_PROXY_AUTH_REQUESTED;
397 } else { 383 } else {
398 // Immediately hand off our SpdyStream to a newly created SpdyHttpStream 384 // Immediately hand off our SpdyStream to a newly created SpdyHttpStream
399 // so that any subsequent SpdyFrames are processed in the context of 385 // so that any subsequent SpdyFrames are processed in the context of
400 // the HttpStream, not the socket. 386 // the HttpStream, not the socket.
401 DCHECK(spdy_stream_); 387 DCHECK(spdy_stream_);
402 SpdyStream* stream = spdy_stream_; 388 SpdyStream* stream = spdy_stream_;
403 spdy_stream_ = NULL; 389 spdy_stream_ = NULL;
404 response_stream_.reset(new SpdyHttpStream(NULL, false)); 390 response_stream_.reset(new SpdyHttpStream(NULL, false));
405 response_stream_->InitializeWithExistingStream(stream); 391 response_stream_->InitializeWithExistingStream(stream);
406 next_state_ = STATE_DISCONNECTED; 392 next_state_ = STATE_DISCONNECTED;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 507 }
522 // This may have been deleted by read_callback_, so check first. 508 // This may have been deleted by read_callback_, so check first.
523 if (weak_ptr && !write_callback.is_null()) 509 if (weak_ptr && !write_callback.is_null())
524 write_callback.Run(ERR_CONNECTION_CLOSED); 510 write_callback.Run(ERR_CONNECTION_CLOSED);
525 } 511 }
526 512
527 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { 513 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) {
528 } 514 }
529 515
530 } // namespace net 516 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_proxy_client_socket.h ('k') | net/spdy/spdy_proxy_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698