| 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_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 GrowableIOBuffer* read_buffer, | 201 GrowableIOBuffer* read_buffer, |
| 202 const BoundNetLog& net_log) | 202 const BoundNetLog& net_log) |
| 203 : io_state_(STATE_NONE), | 203 : io_state_(STATE_NONE), |
| 204 request_(request), | 204 request_(request), |
| 205 request_headers_(nullptr), | 205 request_headers_(nullptr), |
| 206 request_headers_length_(0), | 206 request_headers_length_(0), |
| 207 read_buf_(read_buffer), | 207 read_buf_(read_buffer), |
| 208 read_buf_unused_offset_(0), | 208 read_buf_unused_offset_(0), |
| 209 response_header_start_offset_(-1), | 209 response_header_start_offset_(-1), |
| 210 received_bytes_(0), | 210 received_bytes_(0), |
| 211 sent_bytes_(0), |
| 211 response_(nullptr), | 212 response_(nullptr), |
| 212 response_body_length_(-1), | 213 response_body_length_(-1), |
| 213 response_body_read_(0), | 214 response_body_read_(0), |
| 214 user_read_buf_(nullptr), | 215 user_read_buf_(nullptr), |
| 215 user_read_buf_len_(0), | 216 user_read_buf_len_(0), |
| 216 connection_(connection), | 217 connection_(connection), |
| 217 net_log_(net_log), | 218 net_log_(net_log), |
| 218 sent_last_chunk_(false), | 219 sent_last_chunk_(false), |
| 219 upload_error_(OK), | 220 upload_error_(OK), |
| 220 weak_ptr_factory_(this) { | 221 weak_ptr_factory_(this) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // an error that this should try reading after, stash the error for now and | 469 // an error that this should try reading after, stash the error for now and |
| 469 // act like the request was successfully sent. | 470 // act like the request was successfully sent. |
| 470 if (request_headers_->BytesConsumed() >= request_headers_length_ && | 471 if (request_headers_->BytesConsumed() >= request_headers_length_ && |
| 471 ShouldTryReadingOnUploadError(result)) { | 472 ShouldTryReadingOnUploadError(result)) { |
| 472 upload_error_ = result; | 473 upload_error_ = result; |
| 473 return OK; | 474 return OK; |
| 474 } | 475 } |
| 475 return result; | 476 return result; |
| 476 } | 477 } |
| 477 | 478 |
| 479 sent_bytes_ += result; |
| 478 request_headers_->DidConsume(result); | 480 request_headers_->DidConsume(result); |
| 479 if (request_headers_->BytesRemaining() > 0) { | 481 if (request_headers_->BytesRemaining() > 0) { |
| 480 io_state_ = STATE_SEND_HEADERS; | 482 io_state_ = STATE_SEND_HEADERS; |
| 481 return OK; | 483 return OK; |
| 482 } | 484 } |
| 483 | 485 |
| 484 if (request_->upload_data_stream != NULL && | 486 if (request_->upload_data_stream != NULL && |
| 485 (request_->upload_data_stream->is_chunked() || | 487 (request_->upload_data_stream->is_chunked() || |
| 486 // !IsEOF() indicates that the body wasn't merged. | 488 // !IsEOF() indicates that the body wasn't merged. |
| 487 (request_->upload_data_stream->size() > 0 && | 489 (request_->upload_data_stream->size() > 0 && |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 if (result < 0) { | 527 if (result < 0) { |
| 526 // If |result| is an error that this should try reading after, stash the | 528 // If |result| is an error that this should try reading after, stash the |
| 527 // error for now and act like the request was successfully sent. | 529 // error for now and act like the request was successfully sent. |
| 528 if (ShouldTryReadingOnUploadError(result)) { | 530 if (ShouldTryReadingOnUploadError(result)) { |
| 529 upload_error_ = result; | 531 upload_error_ = result; |
| 530 return OK; | 532 return OK; |
| 531 } | 533 } |
| 532 return result; | 534 return result; |
| 533 } | 535 } |
| 534 | 536 |
| 537 sent_bytes_ += result; |
| 535 request_body_send_buf_->DidConsume(result); | 538 request_body_send_buf_->DidConsume(result); |
| 536 | 539 |
| 537 io_state_ = STATE_SEND_BODY; | 540 io_state_ = STATE_SEND_BODY; |
| 538 return OK; | 541 return OK; |
| 539 } | 542 } |
| 540 | 543 |
| 541 int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { | 544 int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { |
| 542 // |result| is the result of read from the request body from the last call to | 545 // |result| is the result of read from the request body from the last call to |
| 543 // DoSendBody(). | 546 // DoSendBody(). |
| 544 DCHECK_GE(result, 0); // There won't be errors. | 547 DCHECK_GE(result, 0); // There won't be errors. |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 } | 1138 } |
| 1136 | 1139 |
| 1137 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { | 1140 void HttpStreamParser::ValidateStatusLine(const std::string& status_line) { |
| 1138 HttpStatusLineValidator::StatusLineStatus status = | 1141 HttpStatusLineValidator::StatusLineStatus status = |
| 1139 HttpStatusLineValidator::ValidateStatusLine(status_line); | 1142 HttpStatusLineValidator::ValidateStatusLine(status_line); |
| 1140 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, | 1143 UMA_HISTOGRAM_ENUMERATION("Net.HttpStatusLineStatus", status, |
| 1141 HttpStatusLineValidator::STATUS_LINE_MAX); | 1144 HttpStatusLineValidator::STATUS_LINE_MAX); |
| 1142 } | 1145 } |
| 1143 | 1146 |
| 1144 } // namespace net | 1147 } // namespace net |
| OLD | NEW |