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