Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Side by Side Diff: net/http/http_basic_state.cc

Issue 2298823002: Resetting the HttpRequestInfo pointers in HttpNetworkTransaction and streams (Closed)
Patch Set: Initial patch Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 : read_buf_(new GrowableIOBuffer()), 22 : read_buf_(new GrowableIOBuffer()),
23 connection_(std::move(connection)), 23 connection_(std::move(connection)),
24 using_proxy_(using_proxy), 24 using_proxy_(using_proxy) {}
25 request_info_(NULL) {}
26 25
27 HttpBasicState::~HttpBasicState() {} 26 HttpBasicState::~HttpBasicState() {}
28 27
29 int HttpBasicState::Initialize(const HttpRequestInfo* request_info, 28 int HttpBasicState::Initialize(const HttpRequestInfo* request_info,
30 RequestPriority priority, 29 RequestPriority priority,
31 const BoundNetLog& net_log, 30 const BoundNetLog& net_log,
32 const CompletionCallback& callback) { 31 const CompletionCallback& callback) {
33 DCHECK(!parser_.get()); 32 DCHECK(!parser_.get());
34 request_info_ = request_info; 33 url_ = request_info->url;
34 request_method_ = request_info->method;
35 parser_.reset(new HttpStreamParser( 35 parser_.reset(new HttpStreamParser(
36 connection_.get(), request_info, read_buf_.get(), net_log)); 36 connection_.get(), request_info, read_buf_.get(), net_log));
37 return OK; 37 return OK;
38 } 38 }
39 39
40 std::unique_ptr<ClientSocketHandle> HttpBasicState::ReleaseConnection() { 40 std::unique_ptr<ClientSocketHandle> HttpBasicState::ReleaseConnection() {
41 return std::move(connection_); 41 return std::move(connection_);
42 } 42 }
43 43
44 scoped_refptr<GrowableIOBuffer> HttpBasicState::read_buf() const { 44 scoped_refptr<GrowableIOBuffer> HttpBasicState::read_buf() const {
45 return read_buf_; 45 return read_buf_;
46 } 46 }
47 47
48 void HttpBasicState::DeleteParser() { parser_.reset(); } 48 void HttpBasicState::DeleteParser() { parser_.reset(); }
49 49
50 std::string HttpBasicState::GenerateRequestLine() const { 50 std::string HttpBasicState::GenerateRequestLine() const {
51 static const char kSuffix[] = " HTTP/1.1\r\n"; 51 static const char kSuffix[] = " HTTP/1.1\r\n";
52 const size_t kSuffixLen = arraysize(kSuffix) - 1; 52 const size_t kSuffixLen = arraysize(kSuffix) - 1;
53 DCHECK(request_info_);
54 const GURL& url = request_info_->url;
55 const std::string path = 53 const std::string path =
56 using_proxy_ ? HttpUtil::SpecForRequest(url) : url.PathForRequest(); 54 using_proxy_ ? HttpUtil::SpecForRequest(url_) : url_.PathForRequest();
57 // Don't use StringPrintf for concatenation because it is very inefficient. 55 // Don't use StringPrintf for concatenation because it is very inefficient.
58 std::string request_line; 56 std::string request_line;
59 const size_t expected_size = request_info_->method.size() + 1 + path.size() + 57 const size_t expected_size =
60 kSuffixLen; 58 request_method_.size() + 1 + path.size() + kSuffixLen;
61 request_line.reserve(expected_size); 59 request_line.reserve(expected_size);
62 request_line.append(request_info_->method); 60 request_line.append(request_method_);
63 request_line.append(1, ' '); 61 request_line.append(1, ' ');
64 request_line.append(path); 62 request_line.append(path);
65 request_line.append(kSuffix, kSuffixLen); 63 request_line.append(kSuffix, kSuffixLen);
66 DCHECK_EQ(expected_size, request_line.size()); 64 DCHECK_EQ(expected_size, request_line.size());
67 return request_line; 65 return request_line;
68 } 66 }
69 67
70 } // namespace net 68 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698