| 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/histogram.h" | 8 #include "base/histogram.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 const HttpRequestInfo* request, |
| 17 GrowableIOBuffer* read_buffer, | 18 GrowableIOBuffer* read_buffer, |
| 18 const BoundNetLog& net_log) | 19 const BoundNetLog& net_log) |
| 19 : io_state_(STATE_NONE), | 20 : io_state_(STATE_NONE), |
| 20 request_(NULL), | 21 request_(request), |
| 21 request_headers_(NULL), | 22 request_headers_(NULL), |
| 22 request_body_(NULL), | 23 request_body_(NULL), |
| 23 read_buf_(read_buffer), | 24 read_buf_(read_buffer), |
| 24 read_buf_unused_offset_(0), | 25 read_buf_unused_offset_(0), |
| 25 response_header_start_offset_(-1), | 26 response_header_start_offset_(-1), |
| 26 response_body_length_(-1), | 27 response_body_length_(-1), |
| 27 response_body_read_(0), | 28 response_body_read_(0), |
| 28 chunked_decoder_(NULL), | 29 chunked_decoder_(NULL), |
| 29 user_read_buf_(NULL), | 30 user_read_buf_(NULL), |
| 30 user_read_buf_len_(0), | 31 user_read_buf_len_(0), |
| 31 user_callback_(NULL), | 32 user_callback_(NULL), |
| 32 connection_(connection), | 33 connection_(connection), |
| 33 net_log_(net_log), | 34 net_log_(net_log), |
| 34 ALLOW_THIS_IN_INITIALIZER_LIST( | 35 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 35 io_callback_(this, &HttpStreamParser::OnIOComplete)) { | 36 io_callback_(this, &HttpStreamParser::OnIOComplete)) { |
| 36 DCHECK_EQ(0, read_buffer->offset()); | 37 DCHECK_EQ(0, read_buffer->offset()); |
| 37 } | 38 } |
| 38 | 39 |
| 39 HttpStreamParser::~HttpStreamParser() {} | 40 HttpStreamParser::~HttpStreamParser() {} |
| 40 | 41 |
| 41 int HttpStreamParser::SendRequest(const HttpRequestInfo* request, | 42 int HttpStreamParser::SendRequest(const std::string& headers, |
| 42 const std::string& headers, | |
| 43 UploadDataStream* request_body, | 43 UploadDataStream* request_body, |
| 44 HttpResponseInfo* response, | 44 HttpResponseInfo* response, |
| 45 CompletionCallback* callback) { | 45 CompletionCallback* callback) { |
| 46 DCHECK_EQ(STATE_NONE, io_state_); | 46 DCHECK_EQ(STATE_NONE, io_state_); |
| 47 DCHECK(!user_callback_); | 47 DCHECK(!user_callback_); |
| 48 DCHECK(callback); | 48 DCHECK(callback); |
| 49 DCHECK(response); | 49 DCHECK(response); |
| 50 | 50 |
| 51 request_ = request; | |
| 52 response_ = response; | 51 response_ = response; |
| 53 scoped_refptr<StringIOBuffer> headers_io_buf = new StringIOBuffer(headers); | 52 scoped_refptr<StringIOBuffer> headers_io_buf = new StringIOBuffer(headers); |
| 54 request_headers_ = new DrainableIOBuffer(headers_io_buf, | 53 request_headers_ = new DrainableIOBuffer(headers_io_buf, |
| 55 headers_io_buf->size()); | 54 headers_io_buf->size()); |
| 56 request_body_.reset(request_body); | 55 request_body_.reset(request_body); |
| 57 | 56 |
| 58 io_state_ = STATE_SENDING_HEADERS; | 57 io_state_ = STATE_SENDING_HEADERS; |
| 59 int result = DoLoop(OK); | 58 int result = DoLoop(OK); |
| 60 if (result == ERR_IO_PENDING) | 59 if (result == ERR_IO_PENDING) |
| 61 user_callback_ = callback; | 60 user_callback_ = callback; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 549 |
| 551 bool HttpStreamParser::CanFindEndOfResponse() const { | 550 bool HttpStreamParser::CanFindEndOfResponse() const { |
| 552 return chunked_decoder_.get() || response_body_length_ >= 0; | 551 return chunked_decoder_.get() || response_body_length_ >= 0; |
| 553 } | 552 } |
| 554 | 553 |
| 555 bool HttpStreamParser::IsMoreDataBuffered() const { | 554 bool HttpStreamParser::IsMoreDataBuffered() const { |
| 556 return read_buf_->offset() > read_buf_unused_offset_; | 555 return read_buf_->offset() > read_buf_unused_offset_; |
| 557 } | 556 } |
| 558 | 557 |
| 559 } // namespace net | 558 } // namespace net |
| OLD | NEW |