OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/embedded_test_server/request_handler_util.h" | 5 #include "net/test/embedded_test_server/request_handler_util.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <ctime> | 9 #include <ctime> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 193 |
194 base::FilePath headers_path( | 194 base::FilePath headers_path( |
195 file_path.AddExtension(FILE_PATH_LITERAL("mock-http-headers"))); | 195 file_path.AddExtension(FILE_PATH_LITERAL("mock-http-headers"))); |
196 | 196 |
197 if (base::PathExists(headers_path)) { | 197 if (base::PathExists(headers_path)) { |
198 std::string headers_contents; | 198 std::string headers_contents; |
199 | 199 |
200 if (!base::ReadFileToString(headers_path, &headers_contents)) | 200 if (!base::ReadFileToString(headers_path, &headers_contents)) |
201 return nullptr; | 201 return nullptr; |
202 | 202 |
203 return base::WrapUnique( | 203 return base::MakeUnique<RawHttpResponse>(headers_contents, file_contents); |
204 new RawHttpResponse(headers_contents, file_contents)); | |
205 } | 204 } |
206 | 205 |
207 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | 206 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); |
208 http_response->set_code(HTTP_OK); | 207 http_response->set_code(HTTP_OK); |
209 | 208 |
210 if (request.headers.find("Range") != request.headers.end()) { | 209 if (request.headers.find("Range") != request.headers.end()) { |
211 std::vector<HttpByteRange> ranges; | 210 std::vector<HttpByteRange> ranges; |
212 | 211 |
213 if (HttpUtil::ParseRangeHeader(request.headers.at("Range"), &ranges) && | 212 if (HttpUtil::ParseRangeHeader(request.headers.at("Range"), &ranges) && |
214 ranges.size() == 1) { | 213 ranges.size() == 1) { |
(...skipping 13 matching lines...) Expand all Loading... |
228 | 227 |
229 http_response->set_content_type(GetContentType(file_path)); | 228 http_response->set_content_type(GetContentType(file_path)); |
230 http_response->AddCustomHeader("Accept-Ranges", "bytes"); | 229 http_response->AddCustomHeader("Accept-Ranges", "bytes"); |
231 http_response->AddCustomHeader("ETag", "'" + file_path.MaybeAsASCII() + "'"); | 230 http_response->AddCustomHeader("ETag", "'" + file_path.MaybeAsASCII() + "'"); |
232 http_response->set_content(file_contents); | 231 http_response->set_content(file_contents); |
233 return std::move(http_response); | 232 return std::move(http_response); |
234 } | 233 } |
235 | 234 |
236 } // namespace test_server | 235 } // namespace test_server |
237 } // namespace net | 236 } // namespace net |
OLD | NEW |