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 relative_url(request.relative_url); |
| 53 // A proxy request will have an absolute path. Simulate the proxy by stripping |
| 54 // the scheme, host, and port. |
| 55 GURL relative_gurl(relative_url); |
| 56 if (relative_gurl.is_valid()) |
| 57 relative_url = relative_gurl.PathForRequest(); |
| 58 |
52 // Trim the first byte ('/'). | 59 // Trim the first byte ('/'). |
53 std::string request_path(request.relative_url.substr(1)); | 60 std::string request_path = relative_url.substr(1); |
54 | 61 |
55 // Remove the query string if present. | 62 // Remove the query string if present. |
56 size_t query_pos = request_path.find('?'); | 63 size_t query_pos = request_path.find('?'); |
57 if (query_pos != std::string::npos) | 64 if (query_pos != std::string::npos) |
58 request_path = request_path.substr(0, query_pos); | 65 request_path = request_path.substr(0, query_pos); |
59 | 66 |
60 base::FilePath file_path(server_root.AppendASCII(request_path)); | 67 base::FilePath file_path(server_root.AppendASCII(request_path)); |
61 std::string file_contents; | 68 std::string file_contents; |
62 if (!base::ReadFileToString(file_path, &file_contents)) | 69 if (!base::ReadFileToString(file_path, &file_contents)) |
63 return scoped_ptr<HttpResponse>(); | 70 return scoped_ptr<HttpResponse>(); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 FROM_HERE, closure, run_loop.QuitClosure())) { | 353 FROM_HERE, closure, run_loop.QuitClosure())) { |
347 return false; | 354 return false; |
348 } | 355 } |
349 run_loop.Run(); | 356 run_loop.Run(); |
350 | 357 |
351 return true; | 358 return true; |
352 } | 359 } |
353 | 360 |
354 } // namespace test_server | 361 } // namespace test_server |
355 } // namespace net | 362 } // namespace net |
OLD | NEW |