OLD | NEW |
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_proxy_client_socket.h" | 5 #include "net/http/http_proxy_client_socket.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "net/base/auth.h" | 13 #include "net/base/auth.h" |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/proxy_delegate.h" | 16 #include "net/base/proxy_delegate.h" |
17 #include "net/http/http_basic_stream.h" | 17 #include "net/http/http_basic_stream.h" |
18 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
19 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
20 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
21 #include "net/http/http_stream_parser.h" | 21 #include "net/http/http_stream_parser.h" |
22 #include "net/http/proxy_connect_redirect_http_stream.h" | 22 #include "net/http/proxy_connect_redirect_http_stream.h" |
23 #include "net/log/net_log.h" | 23 #include "net/log/net_log.h" |
| 24 #include "net/log/net_log_event_type.h" |
24 #include "net/socket/client_socket_handle.h" | 25 #include "net/socket/client_socket_handle.h" |
25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
26 | 27 |
27 namespace net { | 28 namespace net { |
28 | 29 |
29 HttpProxyClientSocket::HttpProxyClientSocket( | 30 HttpProxyClientSocket::HttpProxyClientSocket( |
30 ClientSocketHandle* transport_socket, | 31 ClientSocketHandle* transport_socket, |
31 const std::string& user_agent, | 32 const std::string& user_agent, |
32 const HostPortPair& endpoint, | 33 const HostPortPair& endpoint, |
33 const HostPortPair& proxy_server, | 34 const HostPortPair& proxy_server, |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 case STATE_GENERATE_AUTH_TOKEN: | 329 case STATE_GENERATE_AUTH_TOKEN: |
329 DCHECK_EQ(OK, rv); | 330 DCHECK_EQ(OK, rv); |
330 rv = DoGenerateAuthToken(); | 331 rv = DoGenerateAuthToken(); |
331 break; | 332 break; |
332 case STATE_GENERATE_AUTH_TOKEN_COMPLETE: | 333 case STATE_GENERATE_AUTH_TOKEN_COMPLETE: |
333 rv = DoGenerateAuthTokenComplete(rv); | 334 rv = DoGenerateAuthTokenComplete(rv); |
334 break; | 335 break; |
335 case STATE_SEND_REQUEST: | 336 case STATE_SEND_REQUEST: |
336 DCHECK_EQ(OK, rv); | 337 DCHECK_EQ(OK, rv); |
337 net_log_.BeginEvent( | 338 net_log_.BeginEvent( |
338 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_SEND_REQUEST); | 339 NetLogEventType::HTTP_TRANSACTION_TUNNEL_SEND_REQUEST); |
339 rv = DoSendRequest(); | 340 rv = DoSendRequest(); |
340 break; | 341 break; |
341 case STATE_SEND_REQUEST_COMPLETE: | 342 case STATE_SEND_REQUEST_COMPLETE: |
342 rv = DoSendRequestComplete(rv); | 343 rv = DoSendRequestComplete(rv); |
343 net_log_.EndEventWithNetErrorCode( | 344 net_log_.EndEventWithNetErrorCode( |
344 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_SEND_REQUEST, rv); | 345 NetLogEventType::HTTP_TRANSACTION_TUNNEL_SEND_REQUEST, rv); |
345 break; | 346 break; |
346 case STATE_READ_HEADERS: | 347 case STATE_READ_HEADERS: |
347 DCHECK_EQ(OK, rv); | 348 DCHECK_EQ(OK, rv); |
348 net_log_.BeginEvent( | 349 net_log_.BeginEvent( |
349 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS); | 350 NetLogEventType::HTTP_TRANSACTION_TUNNEL_READ_HEADERS); |
350 rv = DoReadHeaders(); | 351 rv = DoReadHeaders(); |
351 break; | 352 break; |
352 case STATE_READ_HEADERS_COMPLETE: | 353 case STATE_READ_HEADERS_COMPLETE: |
353 rv = DoReadHeadersComplete(rv); | 354 rv = DoReadHeadersComplete(rv); |
354 net_log_.EndEventWithNetErrorCode( | 355 net_log_.EndEventWithNetErrorCode( |
355 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS, rv); | 356 NetLogEventType::HTTP_TRANSACTION_TUNNEL_READ_HEADERS, rv); |
356 break; | 357 break; |
357 case STATE_DRAIN_BODY: | 358 case STATE_DRAIN_BODY: |
358 DCHECK_EQ(OK, rv); | 359 DCHECK_EQ(OK, rv); |
359 rv = DoDrainBody(); | 360 rv = DoDrainBody(); |
360 break; | 361 break; |
361 case STATE_DRAIN_BODY_COMPLETE: | 362 case STATE_DRAIN_BODY_COMPLETE: |
362 rv = DoDrainBodyComplete(rv); | 363 rv = DoDrainBodyComplete(rv); |
363 break; | 364 break; |
364 case STATE_DONE: | 365 case STATE_DONE: |
365 break; | 366 break; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 402 } |
402 std::string user_agent; | 403 std::string user_agent; |
403 if (!request_.extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, | 404 if (!request_.extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, |
404 &user_agent)) { | 405 &user_agent)) { |
405 user_agent.clear(); | 406 user_agent.clear(); |
406 } | 407 } |
407 BuildTunnelRequest(endpoint_, authorization_headers, user_agent, | 408 BuildTunnelRequest(endpoint_, authorization_headers, user_agent, |
408 &request_line_, &request_headers_); | 409 &request_line_, &request_headers_); |
409 | 410 |
410 net_log_.AddEvent( | 411 net_log_.AddEvent( |
411 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | 412 NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
412 base::Bind(&HttpRequestHeaders::NetLogCallback, | 413 base::Bind(&HttpRequestHeaders::NetLogCallback, |
413 base::Unretained(&request_headers_), | 414 base::Unretained(&request_headers_), &request_line_)); |
414 &request_line_)); | |
415 } | 415 } |
416 | 416 |
417 parser_buf_ = new GrowableIOBuffer(); | 417 parser_buf_ = new GrowableIOBuffer(); |
418 http_stream_parser_.reset(new HttpStreamParser( | 418 http_stream_parser_.reset(new HttpStreamParser( |
419 transport_.get(), &request_, parser_buf_.get(), net_log_)); | 419 transport_.get(), &request_, parser_buf_.get(), net_log_)); |
420 return http_stream_parser_->SendRequest( | 420 return http_stream_parser_->SendRequest( |
421 request_line_, request_headers_, &response_, io_callback_); | 421 request_line_, request_headers_, &response_, io_callback_); |
422 } | 422 } |
423 | 423 |
424 int HttpProxyClientSocket::DoSendRequestComplete(int result) { | 424 int HttpProxyClientSocket::DoSendRequestComplete(int result) { |
(...skipping 11 matching lines...) Expand all Loading... |
436 | 436 |
437 int HttpProxyClientSocket::DoReadHeadersComplete(int result) { | 437 int HttpProxyClientSocket::DoReadHeadersComplete(int result) { |
438 if (result < 0) | 438 if (result < 0) |
439 return result; | 439 return result; |
440 | 440 |
441 // Require the "HTTP/1.x" status line for SSL CONNECT. | 441 // Require the "HTTP/1.x" status line for SSL CONNECT. |
442 if (response_.headers->GetHttpVersion() < HttpVersion(1, 0)) | 442 if (response_.headers->GetHttpVersion() < HttpVersion(1, 0)) |
443 return ERR_TUNNEL_CONNECTION_FAILED; | 443 return ERR_TUNNEL_CONNECTION_FAILED; |
444 | 444 |
445 net_log_.AddEvent( | 445 net_log_.AddEvent( |
446 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 446 NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
447 base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers)); | 447 base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers)); |
448 | 448 |
449 if (proxy_delegate_) { | 449 if (proxy_delegate_) { |
450 proxy_delegate_->OnTunnelHeadersReceived( | 450 proxy_delegate_->OnTunnelHeadersReceived( |
451 HostPortPair::FromURL(request_.url), | 451 HostPortPair::FromURL(request_.url), |
452 proxy_server_, | 452 proxy_server_, |
453 *response_.headers); | 453 *response_.headers); |
454 } | 454 } |
455 | 455 |
456 switch (response_.headers->response_code()) { | 456 switch (response_.headers->response_code()) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 next_state_ = STATE_DRAIN_BODY; | 525 next_state_ = STATE_DRAIN_BODY; |
526 return OK; | 526 return OK; |
527 } | 527 } |
528 | 528 |
529 return DidDrainBodyForAuthRestart(); | 529 return DidDrainBodyForAuthRestart(); |
530 } | 530 } |
531 | 531 |
532 //---------------------------------------------------------------- | 532 //---------------------------------------------------------------- |
533 | 533 |
534 } // namespace net | 534 } // namespace net |
OLD | NEW |