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/chromium/quic_http_stream.h" | 5 #include "net/quic/chromium/quic_http_stream.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 // Store the serialized request headers. | 267 // Store the serialized request headers. |
268 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, | 268 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, |
269 /*direct=*/true, &request_headers_); | 269 /*direct=*/true, &request_headers_); |
270 | 270 |
271 // Store the request body. | 271 // Store the request body. |
272 request_body_stream_ = request_info_->upload_data_stream; | 272 request_body_stream_ = request_info_->upload_data_stream; |
273 if (request_body_stream_) { | 273 if (request_body_stream_) { |
274 // A request with a body is ineligible for push, so reset the | 274 // A request with a body is ineligible for push, so reset the |
275 // promised stream and request a new stream. | 275 // promised stream and request a new stream. |
276 if (found_promise_) { | 276 if (found_promise_) { |
277 found_promise_ = false; | |
278 std::string url(request_info_->url.spec()); | 277 std::string url(request_info_->url.spec()); |
279 QuicClientPromisedInfo* promised = | 278 QuicClientPromisedInfo* promised = |
280 session_->push_promise_index()->GetPromised(url); | 279 session_->push_promise_index()->GetPromised(url); |
281 if (promised != nullptr) { | 280 if (promised != nullptr) { |
282 session_->ResetPromised(promised->id(), QUIC_STREAM_CANCELLED); | 281 session_->ResetPromised(promised->id(), QUIC_STREAM_CANCELLED); |
283 } | 282 } |
284 } | 283 } |
285 | 284 |
286 // TODO(rch): Can we be more precise about when to allocate | 285 // TODO(rch): Can we be more precise about when to allocate |
287 // raw_request_body_buf_. Removed the following check. DoReadRequestBody() | 286 // raw_request_body_buf_. Removed the following check. DoReadRequestBody() |
288 // was being called even if we didn't yet allocate raw_request_body_buf_. | 287 // was being called even if we didn't yet allocate raw_request_body_buf_. |
289 // && (request_body_stream_->size() || | 288 // && (request_body_stream_->size() || |
290 // request_body_stream_->is_chunked())) | 289 // request_body_stream_->is_chunked())) |
291 // Use 10 packets as the body buffer size to give enough space to | 290 // Use 10 packets as the body buffer size to give enough space to |
292 // help ensure we don't often send out partial packets. | 291 // help ensure we don't often send out partial packets. |
293 raw_request_body_buf_ = | 292 raw_request_body_buf_ = |
294 new IOBufferWithSize(static_cast<size_t>(10 * kMaxPacketSize)); | 293 new IOBufferWithSize(static_cast<size_t>(10 * kMaxPacketSize)); |
295 // The request body buffer is empty at first. | 294 // The request body buffer is empty at first. |
296 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_.get(), 0); | 295 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_.get(), 0); |
297 } | 296 } |
298 | 297 |
299 // Store the response info. | 298 // Store the response info. |
300 response_info_ = response; | 299 response_info_ = response; |
301 | 300 |
302 int rv; | 301 int rv; |
303 | 302 |
304 if (found_promise_) { | 303 if (found_promise_) { |
305 next_state_ = STATE_HANDLE_PROMISE; | 304 if (!request_body_stream_) { |
305 next_state_ = STATE_HANDLE_PROMISE; | |
306 } else { | |
307 found_promise_ = false; | |
308 next_state_ = STATE_REQUEST_STREAM; | |
309 } | |
306 } else { | 310 } else { |
307 next_state_ = STATE_SET_REQUEST_PRIORITY; | 311 next_state_ = STATE_SET_REQUEST_PRIORITY; |
Ryan Hamilton
2017/04/06 19:46:48
nit: to reduce the nesting, can you do:
if (!foun
Buck
2017/04/06 19:59:55
Done.
| |
308 } | 312 } |
309 rv = DoLoop(OK); | 313 rv = DoLoop(OK); |
310 | 314 |
311 if (rv == ERR_IO_PENDING) | 315 if (rv == ERR_IO_PENDING) |
312 callback_ = callback; | 316 callback_ = callback; |
313 | 317 |
314 return rv > 0 ? OK : rv; | 318 return rv > 0 ? OK : rv; |
315 } | 319 } |
316 | 320 |
317 int QuicHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { | 321 int QuicHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 // If |response_info_| is null then the request has not been sent, so | 873 // If |response_info_| is null then the request has not been sent, so |
870 // return ERR_CONNECTION_CLOSED to permit HttpNetworkTransaction to | 874 // return ERR_CONNECTION_CLOSED to permit HttpNetworkTransaction to |
871 // retry the request. | 875 // retry the request. |
872 if (!response_info_) | 876 if (!response_info_) |
873 return ERR_CONNECTION_CLOSED; | 877 return ERR_CONNECTION_CLOSED; |
874 | 878 |
875 return ERR_QUIC_PROTOCOL_ERROR; | 879 return ERR_QUIC_PROTOCOL_ERROR; |
876 } | 880 } |
877 | 881 |
878 } // namespace net | 882 } // namespace net |
OLD | NEW |