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 "components/update_client/url_request_post_interceptor.h" | 5 #include "components/update_client/url_request_post_interceptor.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "components/update_client/test_configurator.h" | 12 #include "components/update_client/test_configurator.h" |
13 #include "net/base/upload_bytes_element_reader.h" | 13 #include "net/base/upload_bytes_element_reader.h" |
14 #include "net/base/upload_data_stream.h" | 14 #include "net/base/upload_data_stream.h" |
15 #include "net/http/http_response_headers.h" | |
16 #include "net/http/http_util.h" | |
15 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
16 #include "net/url_request/url_request_filter.h" | 18 #include "net/url_request/url_request_filter.h" |
17 #include "net/url_request/url_request_interceptor.h" | 19 #include "net/url_request/url_request_interceptor.h" |
18 #include "net/url_request/url_request_simple_job.h" | 20 #include "net/url_request/url_request_simple_job.h" |
19 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
20 | 22 |
21 namespace update_client { | 23 namespace update_client { |
22 | 24 |
23 // Returns a canned response. | 25 // Returns a canned response. |
24 class URLRequestMockJob : public net::URLRequestSimpleJob { | 26 class URLRequestMockJob : public net::URLRequestSimpleJob { |
25 public: | 27 public: |
26 URLRequestMockJob(net::URLRequest* request, | 28 URLRequestMockJob(net::URLRequest* request, |
27 net::NetworkDelegate* network_delegate, | 29 net::NetworkDelegate* network_delegate, |
28 int response_code, | 30 int response_code, |
29 const std::string& response_body) | 31 const std::string& response_body) |
30 : net::URLRequestSimpleJob(request, network_delegate), | 32 : net::URLRequestSimpleJob(request, network_delegate), |
31 response_code_(response_code), | 33 response_code_(response_code), |
32 response_body_(response_body) {} | 34 response_body_(response_body) {} |
33 | 35 |
34 protected: | 36 protected: |
35 int GetResponseCode() const override { return response_code_; } | 37 void GetResponseInfo(net::HttpResponseInfo* info) override { |
38 std::string headers = | |
Sorin Jianu
2017/04/21 19:56:27
can be declared const.
mmenke
2017/04/21 20:03:03
Done.
| |
39 base::StringPrintf("HTTP/1.1 %i OK\r\n\r\n", response_code_); | |
40 info->headers = new net::HttpResponseHeaders( | |
Sorin Jianu
2017/04/21 19:56:27
Most likely, we could use base::MakeShared to avoi
mmenke
2017/04/21 20:03:03
Done.
| |
41 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.length())); | |
42 } | |
36 | 43 |
37 int GetData(std::string* mime_type, | 44 int GetData(std::string* mime_type, |
38 std::string* charset, | 45 std::string* charset, |
39 std::string* data, | 46 std::string* data, |
40 const net::CompletionCallback& callback) const override { | 47 const net::CompletionCallback& callback) const override { |
41 mime_type->assign("text/plain"); | 48 mime_type->assign("text/plain"); |
42 charset->assign("US-ASCII"); | 49 charset->assign("US-ASCII"); |
43 data->assign(response_body_); | 50 data->assign(response_body_); |
44 return net::OK; | 51 return net::OK; |
45 } | 52 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 return CreateInterceptorForPath(POST_INTERCEPT_PATH); | 300 return CreateInterceptorForPath(POST_INTERCEPT_PATH); |
294 } | 301 } |
295 | 302 |
296 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptorForPath( | 303 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptorForPath( |
297 const char* url_path) { | 304 const char* url_path) { |
298 return URLRequestPostInterceptorFactory::CreateInterceptor( | 305 return URLRequestPostInterceptorFactory::CreateInterceptor( |
299 base::FilePath::FromUTF8Unsafe(url_path)); | 306 base::FilePath::FromUTF8Unsafe(url_path)); |
300 } | 307 } |
301 | 308 |
302 } // namespace update_client | 309 } // namespace update_client |
OLD | NEW |