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/quic/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } while (next_state_ != STATE_NONE && next_state_ != STATE_OPEN && | 399 } while (next_state_ != STATE_NONE && next_state_ != STATE_OPEN && |
400 rv != ERR_IO_PENDING); | 400 rv != ERR_IO_PENDING); |
401 | 401 |
402 return rv; | 402 return rv; |
403 } | 403 } |
404 | 404 |
405 int QuicHttpStream::DoSendHeaders() { | 405 int QuicHttpStream::DoSendHeaders() { |
406 if (!stream_) | 406 if (!stream_) |
407 return ERR_UNEXPECTED; | 407 return ERR_UNEXPECTED; |
408 | 408 |
409 if (request_.empty() && !stream_->CanWrite( | 409 if (stream_->version() <= QUIC_VERSION_12) { |
410 base::Bind(&QuicHttpStream::OnIOComplete, | 410 if (request_.empty() && !stream_->CanWrite( |
411 weak_factory_.GetWeakPtr()))) { | 411 base::Bind(&QuicHttpStream::OnIOComplete, |
412 // Do not compress headers unless it is likely that they can be sent. | 412 weak_factory_.GetWeakPtr()))) { |
413 next_state_ = STATE_SEND_HEADERS; | 413 // Do not compress headers unless it is likely that they can be sent. |
414 return ERR_IO_PENDING; | 414 next_state_ = STATE_SEND_HEADERS; |
| 415 return ERR_IO_PENDING; |
| 416 } |
| 417 request_ = stream_->compressor()->CompressHeadersWithPriority( |
| 418 ConvertRequestPriorityToQuicPriority(priority_), request_headers_); |
415 } | 419 } |
416 request_ = stream_->compressor()->CompressHeadersWithPriority( | |
417 ConvertRequestPriorityToQuicPriority(priority_), request_headers_); | |
418 | |
419 // Log the actual request with the URL Request's net log. | 420 // Log the actual request with the URL Request's net log. |
420 stream_net_log_.AddEvent( | 421 stream_net_log_.AddEvent( |
421 NetLog::TYPE_HTTP_TRANSACTION_SPDY_SEND_REQUEST_HEADERS, | 422 NetLog::TYPE_HTTP_TRANSACTION_SPDY_SEND_REQUEST_HEADERS, |
422 base::Bind(&SpdyHeaderBlockNetLogCallback, &request_headers_)); | 423 base::Bind(&SpdyHeaderBlockNetLogCallback, &request_headers_)); |
423 // Also log to the QuicSession's net log. | 424 // Also log to the QuicSession's net log. |
424 stream_->net_log().AddEvent( | 425 stream_->net_log().AddEvent( |
425 NetLog::TYPE_QUIC_HTTP_STREAM_SEND_REQUEST_HEADERS, | 426 NetLog::TYPE_QUIC_HTTP_STREAM_SEND_REQUEST_HEADERS, |
426 base::Bind(&SpdyHeaderBlockNetLogCallback, &request_headers_)); | 427 base::Bind(&SpdyHeaderBlockNetLogCallback, &request_headers_)); |
427 request_headers_.clear(); | |
428 | 428 |
429 bool has_upload_data = request_body_stream_ != NULL; | 429 bool has_upload_data = request_body_stream_ != NULL; |
430 | 430 |
431 next_state_ = STATE_SEND_HEADERS_COMPLETE; | 431 next_state_ = STATE_SEND_HEADERS_COMPLETE; |
432 return stream_->WriteStreamData( | 432 int rv = (stream_->version() > QUIC_VERSION_12) ? |
433 request_, !has_upload_data, | 433 stream_->WriteHeaders(request_headers_, !has_upload_data) : |
434 base::Bind(&QuicHttpStream::OnIOComplete, weak_factory_.GetWeakPtr())); | 434 stream_->WriteStreamData(request_, !has_upload_data, |
| 435 base::Bind(&QuicHttpStream::OnIOComplete, |
| 436 weak_factory_.GetWeakPtr())); |
| 437 request_headers_.clear(); |
| 438 return rv; |
435 } | 439 } |
436 | 440 |
437 int QuicHttpStream::DoSendHeadersComplete(int rv) { | 441 int QuicHttpStream::DoSendHeadersComplete(int rv) { |
438 if (rv < 0) | 442 if (rv < 0) |
439 return rv; | 443 return rv; |
440 | 444 |
441 next_state_ = request_body_stream_ ? | 445 next_state_ = request_body_stream_ ? |
442 STATE_READ_REQUEST_BODY : STATE_OPEN; | 446 STATE_READ_REQUEST_BODY : STATE_OPEN; |
443 | 447 |
444 return OK; | 448 return OK; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 550 |
547 void QuicHttpStream::BufferResponseBody(const char* data, int length) { | 551 void QuicHttpStream::BufferResponseBody(const char* data, int length) { |
548 if (length == 0) | 552 if (length == 0) |
549 return; | 553 return; |
550 IOBufferWithSize* io_buffer = new IOBufferWithSize(length); | 554 IOBufferWithSize* io_buffer = new IOBufferWithSize(length); |
551 memcpy(io_buffer->data(), data, length); | 555 memcpy(io_buffer->data(), data, length); |
552 response_body_.push_back(make_scoped_refptr(io_buffer)); | 556 response_body_.push_back(make_scoped_refptr(io_buffer)); |
553 } | 557 } |
554 | 558 |
555 } // namespace net | 559 } // namespace net |
OLD | NEW |