OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/url_request/url_request_mock_http_job.h" | 5 #include "net/test/url_request/url_request_mock_http_job.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 task_runner_.get(), | 182 task_runner_.get(), |
183 FROM_HERE, | 183 FROM_HERE, |
184 base::Bind(&DoFileIO, file_path_), | 184 base::Bind(&DoFileIO, file_path_), |
185 base::Bind(&URLRequestMockHTTPJob::SetHeadersAndStart, | 185 base::Bind(&URLRequestMockHTTPJob::SetHeadersAndStart, |
186 weak_ptr_factory_.GetWeakPtr())); | 186 weak_ptr_factory_.GetWeakPtr())); |
187 } | 187 } |
188 | 188 |
189 void URLRequestMockHTTPJob::SetHeadersAndStart(const std::string& raw_headers) { | 189 void URLRequestMockHTTPJob::SetHeadersAndStart(const std::string& raw_headers) { |
190 raw_headers_ = raw_headers; | 190 raw_headers_ = raw_headers; |
191 // Handle CRLF line-endings. | 191 // Handle CRLF line-endings. |
192 ReplaceSubstringsAfterOffset(&raw_headers_, 0, "\r\n", "\n"); | 192 base::ReplaceSubstringsAfterOffset(&raw_headers_, 0, "\r\n", "\n"); |
193 // ParseRawHeaders expects \0 to end each header line. | 193 // ParseRawHeaders expects \0 to end each header line. |
194 ReplaceSubstringsAfterOffset(&raw_headers_, 0, "\n", std::string("\0", 1)); | 194 base::ReplaceSubstringsAfterOffset( |
| 195 &raw_headers_, 0, "\n", base::StringPiece("\0", 1)); |
195 URLRequestFileJob::Start(); | 196 URLRequestFileJob::Start(); |
196 } | 197 } |
197 | 198 |
198 // Private const version. | 199 // Private const version. |
199 void URLRequestMockHTTPJob::GetResponseInfoConst(HttpResponseInfo* info) const { | 200 void URLRequestMockHTTPJob::GetResponseInfoConst(HttpResponseInfo* info) const { |
200 info->headers = new HttpResponseHeaders(raw_headers_); | 201 info->headers = new HttpResponseHeaders(raw_headers_); |
201 } | 202 } |
202 | 203 |
203 bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const { | 204 bool URLRequestMockHTTPJob::GetMimeType(std::string* mime_type) const { |
204 HttpResponseInfo info; | 205 HttpResponseInfo info; |
(...skipping 10 matching lines...) Expand all Loading... |
215 return URLRequestJob::GetResponseCode(); | 216 return URLRequestJob::GetResponseCode(); |
216 } | 217 } |
217 | 218 |
218 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { | 219 bool URLRequestMockHTTPJob::GetCharset(std::string* charset) { |
219 HttpResponseInfo info; | 220 HttpResponseInfo info; |
220 GetResponseInfo(&info); | 221 GetResponseInfo(&info); |
221 return info.headers.get() && info.headers->GetCharset(charset); | 222 return info.headers.get() && info.headers->GetCharset(charset); |
222 } | 223 } |
223 | 224 |
224 } // namespace net | 225 } // namespace net |
OLD | NEW |