OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "headless/public/util/http_url_fetcher.h" | 5 #include "headless/public/util/http_url_fetcher.h" |
6 | 6 |
| 7 #include "net/base/elements_upload_data_stream.h" |
7 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "net/base/upload_bytes_element_reader.h" |
8 #include "net/cert/cert_status_flags.h" | 10 #include "net/cert/cert_status_flags.h" |
9 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
10 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
11 #include "net/url_request/url_request_context.h" | 13 #include "net/url_request/url_request_context.h" |
12 | 14 |
13 namespace headless { | 15 namespace headless { |
14 | 16 |
15 class HttpURLFetcher::Delegate : public net::URLRequest::Delegate { | 17 class HttpURLFetcher::Delegate : public net::URLRequest::Delegate { |
16 public: | 18 public: |
17 Delegate(const GURL& rewritten_url, | 19 Delegate(const GURL& rewritten_url, |
18 const std::string& method, | 20 const std::string& method, |
| 21 const std::string& post_data, |
19 const net::HttpRequestHeaders& request_headers, | 22 const net::HttpRequestHeaders& request_headers, |
20 const net::URLRequestContext* url_request_context, | 23 const net::URLRequestContext* url_request_context, |
21 ResultListener* result_listener); | 24 ResultListener* result_listener); |
22 ~Delegate() override; | 25 ~Delegate() override; |
23 | 26 |
24 // URLRequest::Delegate methods: | 27 // URLRequest::Delegate methods: |
25 void OnAuthRequired(net::URLRequest* request, | 28 void OnAuthRequired(net::URLRequest* request, |
26 net::AuthChallengeInfo* auth_info) override; | 29 net::AuthChallengeInfo* auth_info) override; |
27 void OnSSLCertificateError(net::URLRequest* request, | 30 void OnSSLCertificateError(net::URLRequest* request, |
28 const net::SSLInfo& ssl_info, | 31 const net::SSLInfo& ssl_info, |
(...skipping 20 matching lines...) Expand all Loading... |
49 // Holds the bytes read so far. | 52 // Holds the bytes read so far. |
50 std::string bytes_read_so_far_; | 53 std::string bytes_read_so_far_; |
51 | 54 |
52 // The interface kn which to report any results. | 55 // The interface kn which to report any results. |
53 ResultListener* result_listener_; // NOT OWNED. | 56 ResultListener* result_listener_; // NOT OWNED. |
54 }; | 57 }; |
55 | 58 |
56 HttpURLFetcher::Delegate::Delegate( | 59 HttpURLFetcher::Delegate::Delegate( |
57 const GURL& rewritten_url, | 60 const GURL& rewritten_url, |
58 const std::string& method, | 61 const std::string& method, |
| 62 const std::string& post_data, |
59 const net::HttpRequestHeaders& request_headers, | 63 const net::HttpRequestHeaders& request_headers, |
60 const net::URLRequestContext* url_request_context, | 64 const net::URLRequestContext* url_request_context, |
61 ResultListener* result_listener) | 65 ResultListener* result_listener) |
62 : result_code_(net::OK), | 66 : result_code_(net::OK), |
63 buf_(new net::IOBuffer(kBufSize)), | 67 buf_(new net::IOBuffer(kBufSize)), |
64 request_(url_request_context->CreateRequest(rewritten_url, | 68 request_(url_request_context->CreateRequest(rewritten_url, |
65 net::DEFAULT_PRIORITY, | 69 net::DEFAULT_PRIORITY, |
66 this)), | 70 this)), |
67 result_listener_(result_listener) { | 71 result_listener_(result_listener) { |
68 request_->set_method(method); | 72 request_->set_method(method); |
| 73 |
| 74 if (!post_data.empty()) { |
| 75 request_->set_upload(net::ElementsUploadDataStream::CreateWithReader( |
| 76 base::MakeUnique<net::UploadBytesElementReader>(post_data.data(), |
| 77 post_data.size()), |
| 78 0)); |
| 79 } |
| 80 |
69 request_->SetExtraRequestHeaders(request_headers); | 81 request_->SetExtraRequestHeaders(request_headers); |
70 request_->Start(); | 82 request_->Start(); |
71 } | 83 } |
72 | 84 |
73 HttpURLFetcher::Delegate::~Delegate() {} | 85 HttpURLFetcher::Delegate::~Delegate() {} |
74 | 86 |
75 void HttpURLFetcher::Delegate::OnAuthRequired( | 87 void HttpURLFetcher::Delegate::OnAuthRequired( |
76 net::URLRequest* request, | 88 net::URLRequest* request, |
77 net::AuthChallengeInfo* auth_info) { | 89 net::AuthChallengeInfo* auth_info) { |
78 DCHECK_EQ(request, request_.get()); | 90 DCHECK_EQ(request, request_.get()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 188 } |
177 | 189 |
178 HttpURLFetcher::HttpURLFetcher( | 190 HttpURLFetcher::HttpURLFetcher( |
179 const net::URLRequestContext* url_request_context) | 191 const net::URLRequestContext* url_request_context) |
180 : url_request_context_(url_request_context) {} | 192 : url_request_context_(url_request_context) {} |
181 | 193 |
182 HttpURLFetcher::~HttpURLFetcher() {} | 194 HttpURLFetcher::~HttpURLFetcher() {} |
183 | 195 |
184 void HttpURLFetcher::StartFetch(const GURL& rewritten_url, | 196 void HttpURLFetcher::StartFetch(const GURL& rewritten_url, |
185 const std::string& method, | 197 const std::string& method, |
| 198 const std::string& post_data, |
186 const net::HttpRequestHeaders& request_headers, | 199 const net::HttpRequestHeaders& request_headers, |
187 const std::string& devtools_request_id, | |
188 ResultListener* result_listener) { | 200 ResultListener* result_listener) { |
189 delegate_.reset(new Delegate(rewritten_url, method, request_headers, | 201 delegate_.reset(new Delegate(rewritten_url, method, post_data, |
190 url_request_context_, result_listener)); | 202 request_headers, url_request_context_, |
| 203 result_listener)); |
191 } | 204 } |
192 | 205 |
193 } // namespace headless | 206 } // namespace headless |
OLD | NEW |