| 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 const BoundNetLog& net_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 read_buf_(read_buffer), | 23 read_buf_(read_buffer), |
| 24 read_buf_unused_offset_(0), | 24 read_buf_unused_offset_(0), |
| 25 response_header_start_offset_(-1), | 25 response_header_start_offset_(-1), |
| 26 response_body_length_(-1), | 26 response_body_length_(-1), |
| 27 response_body_read_(0), | 27 response_body_read_(0), |
| 28 chunked_decoder_(NULL), | 28 chunked_decoder_(NULL), |
| 29 user_read_buf_(NULL), | 29 user_read_buf_(NULL), |
| 30 user_read_buf_len_(0), | 30 user_read_buf_len_(0), |
| 31 user_callback_(NULL), | 31 user_callback_(NULL), |
| 32 connection_(connection), | 32 connection_(connection), |
| 33 load_log_(load_log), | 33 net_log_(net_log), |
| 34 ALLOW_THIS_IN_INITIALIZER_LIST( | 34 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 35 io_callback_(this, &HttpStreamParser::OnIOComplete)) { | 35 io_callback_(this, &HttpStreamParser::OnIOComplete)) { |
| 36 DCHECK_EQ(0, read_buffer->offset()); | 36 DCHECK_EQ(0, read_buffer->offset()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 int HttpStreamParser::SendRequest(const HttpRequestInfo* request, | 39 int HttpStreamParser::SendRequest(const HttpRequestInfo* request, |
| 40 const std::string& headers, | 40 const std::string& headers, |
| 41 UploadDataStream* request_body, | 41 UploadDataStream* request_body, |
| 42 HttpResponseInfo* response, | 42 HttpResponseInfo* response, |
| 43 CompletionCallback* callback) { | 43 CompletionCallback* callback) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 else | 141 else |
| 142 result = DoSendBody(result); | 142 result = DoSendBody(result); |
| 143 TRACE_EVENT_END("http.write_body", request_, request_->url.spec()); | 143 TRACE_EVENT_END("http.write_body", request_, request_->url.spec()); |
| 144 break; | 144 break; |
| 145 case STATE_REQUEST_SENT: | 145 case STATE_REQUEST_SENT: |
| 146 DCHECK(result != ERR_IO_PENDING); | 146 DCHECK(result != ERR_IO_PENDING); |
| 147 can_do_more = false; | 147 can_do_more = false; |
| 148 break; | 148 break; |
| 149 case STATE_READ_HEADERS: | 149 case STATE_READ_HEADERS: |
| 150 TRACE_EVENT_BEGIN("http.read_headers", request_, request_->url.spec()); | 150 TRACE_EVENT_BEGIN("http.read_headers", request_, request_->url.spec()); |
| 151 LoadLog::BeginEvent(load_log_, | 151 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS); |
| 152 LoadLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS); | |
| 153 result = DoReadHeaders(); | 152 result = DoReadHeaders(); |
| 154 break; | 153 break; |
| 155 case STATE_READ_HEADERS_COMPLETE: | 154 case STATE_READ_HEADERS_COMPLETE: |
| 156 result = DoReadHeadersComplete(result); | 155 result = DoReadHeadersComplete(result); |
| 157 LoadLog::EndEvent(load_log_, | 156 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS); |
| 158 LoadLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS); | |
| 159 TRACE_EVENT_END("http.read_headers", request_, request_->url.spec()); | 157 TRACE_EVENT_END("http.read_headers", request_, request_->url.spec()); |
| 160 break; | 158 break; |
| 161 case STATE_BODY_PENDING: | 159 case STATE_BODY_PENDING: |
| 162 DCHECK(result != ERR_IO_PENDING); | 160 DCHECK(result != ERR_IO_PENDING); |
| 163 can_do_more = false; | 161 can_do_more = false; |
| 164 break; | 162 break; |
| 165 case STATE_READ_BODY: | 163 case STATE_READ_BODY: |
| 166 TRACE_EVENT_BEGIN("http.read_body", request_, request_->url.spec()); | 164 TRACE_EVENT_BEGIN("http.read_body", request_, request_->url.spec()); |
| 167 result = DoReadBody(); | 165 result = DoReadBody(); |
| 168 // DoReadBodyComplete handles error conditions. | 166 // DoReadBodyComplete handles error conditions. |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 | 531 |
| 534 bool HttpStreamParser::CanFindEndOfResponse() const { | 532 bool HttpStreamParser::CanFindEndOfResponse() const { |
| 535 return chunked_decoder_.get() || response_body_length_ >= 0; | 533 return chunked_decoder_.get() || response_body_length_ >= 0; |
| 536 } | 534 } |
| 537 | 535 |
| 538 bool HttpStreamParser::IsMoreDataBuffered() const { | 536 bool HttpStreamParser::IsMoreDataBuffered() const { |
| 539 return read_buf_->offset() > read_buf_unused_offset_; | 537 return read_buf_->offset() > read_buf_unused_offset_; |
| 540 } | 538 } |
| 541 | 539 |
| 542 } // namespace net | 540 } // namespace net |
| OLD | NEW |