[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1 | // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/http/http_basic_stream.h" |
| 6 | |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame^] | 7 | #include "net/base/io_buffer.h" |
| 8 | #include "net/base/net_errors.h" |
| 9 | #include "net/http/http_stream_parser.h" |
| 10 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11 | namespace net { |
| 12 | |
[email protected] | c638a85a | 2010-07-29 18:41:40 | [diff] [blame] | 13 | HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 14 | : read_buf_(new GrowableIOBuffer()), |
[email protected] | c638a85a | 2010-07-29 18:41:40 | [diff] [blame] | 15 | connection_(connection) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 16 | } |
| 17 | |
[email protected] | c638a85a | 2010-07-29 18:41:40 | [diff] [blame] | 18 | int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, |
| 19 | const BoundNetLog& net_log, |
| 20 | CompletionCallback* callback) { |
| 21 | parser_.reset(new HttpStreamParser(connection_, request_info, |
| 22 | read_buf_, net_log)); |
| 23 | connection_ = NULL; |
| 24 | return OK; |
| 25 | } |
| 26 | |
| 27 | |
| 28 | int HttpBasicStream::SendRequest(const std::string& headers, |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 29 | UploadDataStream* request_body, |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 30 | HttpResponseInfo* response, |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 31 | CompletionCallback* callback) { |
[email protected] | c638a85a | 2010-07-29 18:41:40 | [diff] [blame] | 32 | DCHECK(parser_.get()); |
| 33 | return parser_->SendRequest(headers, request_body, response, callback); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 34 | } |
| 35 | |
[email protected] | 6d22a97 | 2010-07-21 15:47:19 | [diff] [blame] | 36 | HttpBasicStream::~HttpBasicStream() {} |
| 37 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 38 | uint64 HttpBasicStream::GetUploadProgress() const { |
| 39 | return parser_->GetUploadProgress(); |
| 40 | } |
| 41 | |
| 42 | int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) { |
| 43 | return parser_->ReadResponseHeaders(callback); |
| 44 | } |
| 45 | |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame^] | 46 | const HttpResponseInfo* HttpBasicStream::GetResponseInfo() const { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 47 | return parser_->GetResponseInfo(); |
| 48 | } |
| 49 | |
| 50 | int HttpBasicStream::ReadResponseBody(IOBuffer* buf, int buf_len, |
| 51 | CompletionCallback* callback) { |
| 52 | return parser_->ReadResponseBody(buf, buf_len, callback); |
| 53 | } |
| 54 | |
| 55 | bool HttpBasicStream::IsResponseBodyComplete() const { |
| 56 | return parser_->IsResponseBodyComplete(); |
| 57 | } |
| 58 | |
| 59 | bool HttpBasicStream::CanFindEndOfResponse() const { |
| 60 | return parser_->CanFindEndOfResponse(); |
| 61 | } |
| 62 | |
| 63 | bool HttpBasicStream::IsMoreDataBuffered() const { |
| 64 | return parser_->IsMoreDataBuffered(); |
| 65 | } |
| 66 | |
| 67 | } // namespace net |