| 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/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
| 8 #include "net/cert/cert_status_flags.h" | 8 #include "net/cert/cert_status_flags.h" |
| 9 #include "net/http/http_response_headers.h" |
| 9 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| 10 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
| 11 | 12 |
| 12 namespace headless { | 13 namespace headless { |
| 13 | 14 |
| 14 class HttpURLFetcher::Delegate : public net::URLRequest::Delegate { | 15 class HttpURLFetcher::Delegate : public net::URLRequest::Delegate { |
| 15 public: | 16 public: |
| 16 Delegate(const GURL& rewritten_url, | 17 Delegate(const GURL& rewritten_url, |
| 17 const std::string& method, | 18 const std::string& method, |
| 18 const net::HttpRequestHeaders& request_headers, | 19 const net::HttpRequestHeaders& request_headers, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (result_code_ != net::OK) { | 159 if (result_code_ != net::OK) { |
| 159 result_listener_->OnFetchStartError(static_cast<net::Error>(result_code_)); | 160 result_listener_->OnFetchStartError(static_cast<net::Error>(result_code_)); |
| 160 return; | 161 return; |
| 161 } | 162 } |
| 162 | 163 |
| 163 if (net_error != net::OK) { | 164 if (net_error != net::OK) { |
| 164 result_listener_->OnFetchStartError(static_cast<net::Error>(net_error)); | 165 result_listener_->OnFetchStartError(static_cast<net::Error>(net_error)); |
| 165 return; | 166 return; |
| 166 } | 167 } |
| 167 | 168 |
| 168 result_listener_->OnFetchCompleteExtractHeaders( | 169 // TODO(alexclarke) apart from the headers there's a lot of stuff in |
| 169 request->url(), request->GetResponseCode(), bytes_read_so_far_.c_str(), | 170 // |request->response_info()| that we drop here. Find a way to pipe it |
| 170 bytes_read_so_far_.size()); | 171 // through. |
| 172 result_listener_->OnFetchComplete( |
| 173 request->url(), request->GetResponseCode(), |
| 174 request->response_info().headers, |
| 175 bytes_read_so_far_.c_str(), bytes_read_so_far_.size()); |
| 171 } | 176 } |
| 172 | 177 |
| 173 HttpURLFetcher::HttpURLFetcher( | 178 HttpURLFetcher::HttpURLFetcher( |
| 174 const net::URLRequestContext* url_request_context) | 179 const net::URLRequestContext* url_request_context) |
| 175 : url_request_context_(url_request_context) {} | 180 : url_request_context_(url_request_context) {} |
| 176 | 181 |
| 177 HttpURLFetcher::~HttpURLFetcher() {} | 182 HttpURLFetcher::~HttpURLFetcher() {} |
| 178 | 183 |
| 179 void HttpURLFetcher::StartFetch(const GURL& rewritten_url, | 184 void HttpURLFetcher::StartFetch(const GURL& rewritten_url, |
| 180 const std::string& method, | 185 const std::string& method, |
| 181 const net::HttpRequestHeaders& request_headers, | 186 const net::HttpRequestHeaders& request_headers, |
| 182 ResultListener* result_listener) { | 187 ResultListener* result_listener) { |
| 183 delegate_.reset(new Delegate(rewritten_url, method, request_headers, | 188 delegate_.reset(new Delegate(rewritten_url, method, request_headers, |
| 184 url_request_context_, result_listener)); | 189 url_request_context_, result_listener)); |
| 185 } | 190 } |
| 186 | 191 |
| 187 } // namespace headless | 192 } // namespace headless |
| OLD | NEW |