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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 CHECK(!request_body_stream_); | 83 CHECK(!request_body_stream_); |
84 CHECK(!response_info_); | 84 CHECK(!response_info_); |
85 CHECK(!callback.is_null()); | 85 CHECK(!callback.is_null()); |
86 CHECK(response); | 86 CHECK(response); |
87 | 87 |
88 QuicPriority priority = ConvertRequestPriorityToQuicPriority(priority_); | 88 QuicPriority priority = ConvertRequestPriorityToQuicPriority(priority_); |
89 stream_->set_priority(priority); | 89 stream_->set_priority(priority); |
90 // Store the serialized request headers. | 90 // Store the serialized request headers. |
91 SpdyHeaderBlock headers; | 91 SpdyHeaderBlock headers; |
92 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, | 92 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, |
93 &headers, 3, /*direct=*/true); | 93 &headers, SPDY3, /*direct=*/true); |
94 request_ = stream_->compressor()->CompressHeadersWithPriority(priority, | 94 request_ = stream_->compressor()->CompressHeadersWithPriority(priority, |
95 headers); | 95 headers); |
96 // Log the actual request with the URL Request's net log. | 96 // Log the actual request with the URL Request's net log. |
97 stream_net_log_.AddEvent( | 97 stream_net_log_.AddEvent( |
98 NetLog::TYPE_HTTP_TRANSACTION_SPDY_SEND_REQUEST_HEADERS, | 98 NetLog::TYPE_HTTP_TRANSACTION_SPDY_SEND_REQUEST_HEADERS, |
99 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); | 99 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); |
100 // Also log to the QuicSession's net log. | 100 // Also log to the QuicSession's net log. |
101 stream_->net_log().AddEvent( | 101 stream_->net_log().AddEvent( |
102 NetLog::TYPE_QUIC_HTTP_STREAM_SEND_REQUEST_HEADERS, | 102 NetLog::TYPE_QUIC_HTTP_STREAM_SEND_REQUEST_HEADERS, |
103 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); | 103 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 if (delta > 0) { | 497 if (delta > 0) { |
498 BufferResponseBody(data + len, delta); | 498 BufferResponseBody(data + len, delta); |
499 } | 499 } |
500 | 500 |
501 // The URLRequest logs these headers, so only log to the QuicSession's | 501 // The URLRequest logs these headers, so only log to the QuicSession's |
502 // net log. | 502 // net log. |
503 stream_->net_log().AddEvent( | 503 stream_->net_log().AddEvent( |
504 NetLog::TYPE_QUIC_HTTP_STREAM_READ_RESPONSE_HEADERS, | 504 NetLog::TYPE_QUIC_HTTP_STREAM_READ_RESPONSE_HEADERS, |
505 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); | 505 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); |
506 | 506 |
507 if (!SpdyHeadersToHttpResponse(headers, 3, response_info_)) { | 507 if (!SpdyHeadersToHttpResponse(headers, SPDY3, response_info_)) { |
508 DLOG(WARNING) << "Invalid headers"; | 508 DLOG(WARNING) << "Invalid headers"; |
509 return ERR_QUIC_PROTOCOL_ERROR; | 509 return ERR_QUIC_PROTOCOL_ERROR; |
510 } | 510 } |
511 // Put the peer's IP address and port into the response. | 511 // Put the peer's IP address and port into the response. |
512 IPEndPoint address = stream_->GetPeerAddress(); | 512 IPEndPoint address = stream_->GetPeerAddress(); |
513 response_info_->socket_address = HostPortPair::FromIPEndPoint(address); | 513 response_info_->socket_address = HostPortPair::FromIPEndPoint(address); |
514 response_info_->connection_info = | 514 response_info_->connection_info = |
515 HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3; | 515 HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3; |
516 response_info_->vary_data | 516 response_info_->vary_data |
517 .Init(*request_info_, *response_info_->headers.get()); | 517 .Init(*request_info_, *response_info_->headers.get()); |
518 response_info_->was_npn_negotiated = true; | 518 response_info_->was_npn_negotiated = true; |
519 response_info_->npn_negotiated_protocol = "quic/1+spdy/3"; | 519 response_info_->npn_negotiated_protocol = "quic/1+spdy/3"; |
520 response_headers_received_ = true; | 520 response_headers_received_ = true; |
521 | 521 |
522 return OK; | 522 return OK; |
523 } | 523 } |
524 | 524 |
525 void QuicHttpStream::BufferResponseBody(const char* data, int length) { | 525 void QuicHttpStream::BufferResponseBody(const char* data, int length) { |
526 if (length == 0) | 526 if (length == 0) |
527 return; | 527 return; |
528 IOBufferWithSize* io_buffer = new IOBufferWithSize(length); | 528 IOBufferWithSize* io_buffer = new IOBufferWithSize(length); |
529 memcpy(io_buffer->data(), data, length); | 529 memcpy(io_buffer->data(), data, length); |
530 response_body_.push_back(make_scoped_refptr(io_buffer)); | 530 response_body_.push_back(make_scoped_refptr(io_buffer)); |
531 } | 531 } |
532 | 532 |
533 } // namespace net | 533 } // namespace net |
OLD | NEW |