Chromium Code Reviews| 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/embedded_test_server/embedded_test_server.h" | 5 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 DISALLOW_COPY_AND_ASSIGN(CustomHttpResponse); | 42 DISALLOW_COPY_AND_ASSIGN(CustomHttpResponse); |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // Handles |request| by serving a file from under |server_root|. | 45 // Handles |request| by serving a file from under |server_root|. |
| 46 scoped_ptr<HttpResponse> HandleFileRequest( | 46 scoped_ptr<HttpResponse> HandleFileRequest( |
| 47 const base::FilePath& server_root, | 47 const base::FilePath& server_root, |
| 48 const HttpRequest& request) { | 48 const HttpRequest& request) { |
| 49 // This is a test-only server. Ignore I/O thread restrictions. | 49 // This is a test-only server. Ignore I/O thread restrictions. |
| 50 base::ThreadRestrictions::ScopedAllowIO allow_io; | 50 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 51 | 51 |
| 52 std::string request_path(request.relative_url); | |
| 53 // A proxy will have an absolute path. Simulate the proxy by stripping the | |
| 54 // scheme, host, and port. | |
| 55 if (request_path.find("http://127.0.0.1") == 0) { | |
|
mmenke
2014/12/04 18:17:08
Can you just create a GURL from the path, and call
bengr
2014/12/05 23:13:32
Done.
| |
| 56 GURL request_url(request_path); | |
| 57 request_path = request_url.path() + | |
| 58 (request_url.query().empty() ? "" : "?" + request_url.query()); | |
|
mmenke
2014/12/04 18:17:09
request_url.PathForRequest()?
bengr
2014/12/05 23:13:32
Done. (Somehow I missed that method.)
| |
| 59 } | |
| 52 // Trim the first byte ('/'). | 60 // Trim the first byte ('/'). |
| 53 std::string request_path(request.relative_url.substr(1)); | 61 request_path = request_path.substr(1); |
|
mmenke
2014/12/04 18:17:09
Not a big fan of "This is the request_path, no, th
bengr
2014/12/05 23:13:32
Done.
| |
| 54 | 62 |
| 55 // Remove the query string if present. | 63 // Remove the query string if present. |
| 56 size_t query_pos = request_path.find('?'); | 64 size_t query_pos = request_path.find('?'); |
| 57 if (query_pos != std::string::npos) | 65 if (query_pos != std::string::npos) |
| 58 request_path = request_path.substr(0, query_pos); | 66 request_path = request_path.substr(0, query_pos); |
| 59 | 67 |
| 60 base::FilePath file_path(server_root.AppendASCII(request_path)); | 68 base::FilePath file_path(server_root.AppendASCII(request_path)); |
| 61 std::string file_contents; | 69 std::string file_contents; |
| 62 if (!base::ReadFileToString(file_path, &file_contents)) | 70 if (!base::ReadFileToString(file_path, &file_contents)) |
| 63 return scoped_ptr<HttpResponse>(); | 71 return scoped_ptr<HttpResponse>(); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 FROM_HERE, closure, run_loop.QuitClosure())) { | 354 FROM_HERE, closure, run_loop.QuitClosure())) { |
| 347 return false; | 355 return false; |
| 348 } | 356 } |
| 349 run_loop.Run(); | 357 run_loop.Run(); |
| 350 | 358 |
| 351 return true; | 359 return true; |
| 352 } | 360 } |
| 353 | 361 |
| 354 } // namespace test_server | 362 } // namespace test_server |
| 355 } // namespace net | 363 } // namespace net |
| OLD | NEW |