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/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/trace_event.h" | 8 #include "base/trace_event.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/http/http_request_info.h" | 10 #include "net/http/http_request_info.h" |
11 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
12 #include "net/http/http_util.h" | 12 #include "net/http/http_util.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, | 16 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, |
17 GrowableIOBuffer* read_buffer, | 17 GrowableIOBuffer* read_buffer, |
18 LoadLog* load_log) | 18 LoadLog* load_log) |
19 : io_state_(STATE_NONE), | 19 : io_state_(STATE_NONE), |
20 request_(NULL), | 20 request_(NULL), |
21 request_headers_(NULL), | 21 request_headers_(NULL), |
22 request_body_(NULL), | 22 request_body_(NULL), |
23 expected_request_body_result_(0), | |
24 read_buf_(read_buffer), | 23 read_buf_(read_buffer), |
25 read_buf_unused_offset_(0), | 24 read_buf_unused_offset_(0), |
26 response_header_start_offset_(-1), | 25 response_header_start_offset_(-1), |
27 response_body_length_(-1), | 26 response_body_length_(-1), |
28 response_body_read_(0), | 27 response_body_read_(0), |
29 chunked_decoder_(NULL), | 28 chunked_decoder_(NULL), |
30 user_read_buf_(NULL), | 29 user_read_buf_(NULL), |
31 user_read_buf_len_(0), | 30 user_read_buf_len_(0), |
32 user_callback_(NULL), | 31 user_callback_(NULL), |
33 connection_(connection), | 32 connection_(connection), |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } else if (request_body_ != NULL && request_body_->size()) { | 200 } else if (request_body_ != NULL && request_body_->size()) { |
202 io_state_ = STATE_SENDING_BODY; | 201 io_state_ = STATE_SENDING_BODY; |
203 result = OK; | 202 result = OK; |
204 } else { | 203 } else { |
205 io_state_ = STATE_REQUEST_SENT; | 204 io_state_ = STATE_REQUEST_SENT; |
206 } | 205 } |
207 return result; | 206 return result; |
208 } | 207 } |
209 | 208 |
210 int HttpStreamParser::DoSendBody(int result) { | 209 int HttpStreamParser::DoSendBody(int result) { |
211 if (result > 0) { | 210 if (result > 0) |
212 CHECK(result <= expected_request_body_result_) << | |
213 expected_request_body_result_; | |
214 request_body_->DidConsume(result); | 211 request_body_->DidConsume(result); |
215 } | |
216 | 212 |
217 if (!request_body_->eof()) { | 213 if (!request_body_->eof()) { |
218 int buf_len = static_cast<int>(request_body_->buf_len()); | 214 int buf_len = static_cast<int>(request_body_->buf_len()); |
219 expected_request_body_result_ = buf_len; | |
220 result = connection_->socket()->Write(request_body_->buf(), buf_len, | 215 result = connection_->socket()->Write(request_body_->buf(), buf_len, |
221 &io_callback_); | 216 &io_callback_); |
222 } else { | 217 } else { |
223 io_state_ = STATE_REQUEST_SENT; | 218 io_state_ = STATE_REQUEST_SENT; |
224 } | 219 } |
225 return result; | 220 return result; |
226 } | 221 } |
227 | 222 |
228 int HttpStreamParser::DoReadHeaders() { | 223 int HttpStreamParser::DoReadHeaders() { |
229 io_state_ = STATE_READ_HEADERS_COMPLETE; | 224 io_state_ = STATE_READ_HEADERS_COMPLETE; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 526 |
532 bool HttpStreamParser::CanFindEndOfResponse() const { | 527 bool HttpStreamParser::CanFindEndOfResponse() const { |
533 return chunked_decoder_.get() || response_body_length_ >= 0; | 528 return chunked_decoder_.get() || response_body_length_ >= 0; |
534 } | 529 } |
535 | 530 |
536 bool HttpStreamParser::IsMoreDataBuffered() const { | 531 bool HttpStreamParser::IsMoreDataBuffered() const { |
537 return read_buf_->offset() > read_buf_unused_offset_; | 532 return read_buf_->offset() > read_buf_unused_offset_; |
538 } | 533 } |
539 | 534 |
540 } // namespace net | 535 } // namespace net |
OLD | NEW |