| 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/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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 auth_->AddAuthorizationHeader(&authorization_headers); | 303 auth_->AddAuthorizationHeader(&authorization_headers); |
| 304 } | 304 } |
| 305 | 305 |
| 306 std::string request_line; | 306 std::string request_line; |
| 307 HttpRequestHeaders request_headers; | 307 HttpRequestHeaders request_headers; |
| 308 BuildTunnelRequest(request_, authorization_headers, endpoint_, &request_line, | 308 BuildTunnelRequest(request_, authorization_headers, endpoint_, &request_line, |
| 309 &request_headers); | 309 &request_headers); |
| 310 if (net_log_.IsLoggingAllEvents()) { | 310 if (net_log_.IsLoggingAllEvents()) { |
| 311 net_log_.AddEvent( | 311 net_log_.AddEvent( |
| 312 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | 312 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 313 new NetLogHttpRequestParameter( | 313 make_scoped_refptr(new NetLogHttpRequestParameter( |
| 314 request_line, request_headers)); | 314 request_line, request_headers))); |
| 315 } | 315 } |
| 316 | 316 |
| 317 request_.extra_headers.MergeFrom(request_headers); | 317 request_.extra_headers.MergeFrom(request_headers); |
| 318 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock()); | 318 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock()); |
| 319 CreateSpdyHeadersFromHttpRequest(request_, request_headers, headers.get(), | 319 CreateSpdyHeadersFromHttpRequest(request_, request_headers, headers.get(), |
| 320 true); | 320 true); |
| 321 // Reset the URL to be the endpoint of the connection | 321 // Reset the URL to be the endpoint of the connection |
| 322 (*headers)["url"] = endpoint_.ToString(); | 322 (*headers)["url"] = endpoint_.ToString(); |
| 323 headers->erase("scheme"); | 323 headers->erase("scheme"); |
| 324 spdy_stream_->set_spdy_headers(headers); | 324 spdy_stream_->set_spdy_headers(headers); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 343 return result; | 343 return result; |
| 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 next_state_ = STATE_OPEN; | 349 next_state_ = STATE_OPEN; |
| 350 if (net_log_.IsLoggingAllEvents()) { | 350 if (net_log_.IsLoggingAllEvents()) { |
| 351 net_log_.AddEvent( | 351 net_log_.AddEvent( |
| 352 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 352 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 353 new NetLogHttpResponseParameter(response_.headers)); | 353 make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers))); |
| 354 } | 354 } |
| 355 | 355 |
| 356 if (response_.headers->response_code() == 200) | 356 if (response_.headers->response_code() == 200) |
| 357 return OK; | 357 return OK; |
| 358 else | 358 else |
| 359 return ERR_TUNNEL_CONNECTION_FAILED; | 359 return ERR_TUNNEL_CONNECTION_FAILED; |
| 360 } | 360 } |
| 361 | 361 |
| 362 // SpdyStream::Delegate methods: | 362 // SpdyStream::Delegate methods: |
| 363 // Called when SYN frame has been sent. | 363 // Called when SYN frame has been sent. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 399 |
| 400 return OK; | 400 return OK; |
| 401 } | 401 } |
| 402 | 402 |
| 403 // Called when data is received. | 403 // Called when data is received. |
| 404 void SpdyProxyClientSocket::OnDataReceived(const char* data, int length) { | 404 void SpdyProxyClientSocket::OnDataReceived(const char* data, int length) { |
| 405 if (length > 0) { | 405 if (length > 0) { |
| 406 // Save the received data. | 406 // Save the received data. |
| 407 scoped_refptr<IOBuffer> io_buffer(new IOBuffer(length)); | 407 scoped_refptr<IOBuffer> io_buffer(new IOBuffer(length)); |
| 408 memcpy(io_buffer->data(), data, length); | 408 memcpy(io_buffer->data(), data, length); |
| 409 read_buffer_.push_back(new DrainableIOBuffer(io_buffer, length)); | 409 read_buffer_.push_back( |
| 410 make_scoped_refptr(new DrainableIOBuffer(io_buffer, length))); |
| 410 } | 411 } |
| 411 | 412 |
| 412 if (read_callback_) { | 413 if (read_callback_) { |
| 413 int rv = PopulateUserReadBuffer(); | 414 int rv = PopulateUserReadBuffer(); |
| 414 CompletionCallback* c = read_callback_; | 415 CompletionCallback* c = read_callback_; |
| 415 read_callback_ = NULL; | 416 read_callback_ = NULL; |
| 416 user_buffer_ = NULL; | 417 user_buffer_ = NULL; |
| 417 c->Run(rv); | 418 c->Run(rv); |
| 418 } | 419 } |
| 419 } | 420 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 read_callback->Run(status); | 462 read_callback->Run(status); |
| 462 } else if (read_callback_) { | 463 } else if (read_callback_) { |
| 463 // If we have a read_callback, the we need to make sure we call it back | 464 // If we have a read_callback, the we need to make sure we call it back |
| 464 OnDataReceived(NULL, 0); | 465 OnDataReceived(NULL, 0); |
| 465 } | 466 } |
| 466 if (write_callback) | 467 if (write_callback) |
| 467 write_callback->Run(ERR_CONNECTION_CLOSED); | 468 write_callback->Run(ERR_CONNECTION_CLOSED); |
| 468 } | 469 } |
| 469 | 470 |
| 470 } // namespace net | 471 } // namespace net |
| OLD | NEW |