OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_basic_state.h" | 5 #include "net/http/http_basic_state.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.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_body_drainer.h" | 11 #include "net/http/http_response_body_drainer.h" |
12 #include "net/http/http_stream_parser.h" | 12 #include "net/http/http_stream_parser.h" |
13 #include "net/http/http_util.h" | 13 #include "net/http/http_util.h" |
14 #include "net/socket/client_socket_handle.h" | 14 #include "net/socket/client_socket_handle.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 HttpBasicState::HttpBasicState(ClientSocketHandle* connection, bool using_proxy) | 19 HttpBasicState::HttpBasicState(ClientSocketHandle* connection, bool using_proxy) |
20 : read_buf_(new GrowableIOBuffer()), | 20 : read_buf_(new GrowableIOBuffer()), |
21 connection_(connection), | 21 connection_(connection), |
22 using_proxy_(using_proxy), | 22 using_proxy_(using_proxy), |
23 request_info_(NULL) {} | 23 request_info_(NULL) { |
| 24 } |
24 | 25 |
25 HttpBasicState::~HttpBasicState() {} | 26 HttpBasicState::~HttpBasicState() { |
| 27 } |
26 | 28 |
27 int HttpBasicState::Initialize(const HttpRequestInfo* request_info, | 29 int HttpBasicState::Initialize(const HttpRequestInfo* request_info, |
28 RequestPriority priority, | 30 RequestPriority priority, |
29 const BoundNetLog& net_log, | 31 const BoundNetLog& net_log, |
30 const CompletionCallback& callback) { | 32 const CompletionCallback& callback) { |
31 DCHECK(!parser_.get()); | 33 DCHECK(!parser_.get()); |
32 request_info_ = request_info; | 34 request_info_ = request_info; |
33 parser_.reset(new HttpStreamParser( | 35 parser_.reset(new HttpStreamParser( |
34 connection_.get(), request_info, read_buf_.get(), net_log)); | 36 connection_.get(), request_info, read_buf_.get(), net_log)); |
35 return OK; | 37 return OK; |
36 } | 38 } |
37 | 39 |
38 scoped_ptr<ClientSocketHandle> HttpBasicState::ReleaseConnection() { | 40 scoped_ptr<ClientSocketHandle> HttpBasicState::ReleaseConnection() { |
39 return connection_.Pass(); | 41 return connection_.Pass(); |
40 } | 42 } |
41 | 43 |
42 scoped_refptr<GrowableIOBuffer> HttpBasicState::read_buf() const { | 44 scoped_refptr<GrowableIOBuffer> HttpBasicState::read_buf() const { |
43 return read_buf_; | 45 return read_buf_; |
44 } | 46 } |
45 | 47 |
46 void HttpBasicState::DeleteParser() { parser_.reset(); } | 48 void HttpBasicState::DeleteParser() { |
| 49 parser_.reset(); |
| 50 } |
47 | 51 |
48 std::string HttpBasicState::GenerateRequestLine() const { | 52 std::string HttpBasicState::GenerateRequestLine() const { |
49 static const char kSuffix[] = " HTTP/1.1\r\n"; | 53 static const char kSuffix[] = " HTTP/1.1\r\n"; |
50 const size_t kSuffixLen = arraysize(kSuffix) - 1; | 54 const size_t kSuffixLen = arraysize(kSuffix) - 1; |
51 DCHECK(request_info_); | 55 DCHECK(request_info_); |
52 const GURL& url = request_info_->url; | 56 const GURL& url = request_info_->url; |
53 const std::string path = using_proxy_ ? HttpUtil::SpecForRequest(url) | 57 const std::string path = using_proxy_ ? HttpUtil::SpecForRequest(url) |
54 : HttpUtil::PathForRequest(url); | 58 : HttpUtil::PathForRequest(url); |
55 // Don't use StringPrintf for concatenation because it is very inefficient. | 59 // Don't use StringPrintf for concatenation because it is very inefficient. |
56 std::string request_line; | 60 std::string request_line; |
57 const size_t expected_size = request_info_->method.size() + 1 + path.size() + | 61 const size_t expected_size = |
58 kSuffixLen; | 62 request_info_->method.size() + 1 + path.size() + kSuffixLen; |
59 request_line.reserve(expected_size); | 63 request_line.reserve(expected_size); |
60 request_line.append(request_info_->method); | 64 request_line.append(request_info_->method); |
61 request_line.append(1, ' '); | 65 request_line.append(1, ' '); |
62 request_line.append(path); | 66 request_line.append(path); |
63 request_line.append(kSuffix, kSuffixLen); | 67 request_line.append(kSuffix, kSuffixLen); |
64 DCHECK_EQ(expected_size, request_line.size()); | 68 DCHECK_EQ(expected_size, request_line.size()); |
65 return request_line; | 69 return request_line; |
66 } | 70 } |
67 | 71 |
68 } // namespace net | 72 } // namespace net |
OLD | NEW |