Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: net/test/embedded_test_server/embedded_test_server.cc

Issue 1093993003: Allow embedded_test_server to serve from multiple directories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix iOS Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/test/embedded_test_server/embedded_test_server.cc
diff --git a/net/test/embedded_test_server/embedded_test_server.cc b/net/test/embedded_test_server/embedded_test_server.cc
index ac7d3bc14ac74f56b31f3ab83f5c7511f8cf6fb9..49f7c0a21dad9ee888a3f49e79ca0de8fe28b854 100644
--- a/net/test/embedded_test_server/embedded_test_server.cc
+++ b/net/test/embedded_test_server/embedded_test_server.cc
@@ -42,9 +42,9 @@ class CustomHttpResponse : public HttpResponse {
DISALLOW_COPY_AND_ASSIGN(CustomHttpResponse);
};
-// Handles |request| by serving a file from under |server_root|.
+// Handles |request| by serving a file from under |server_roots|.
scoped_ptr<HttpResponse> HandleFileRequest(
- const base::FilePath& server_root,
+ const std::vector<base::FilePath>& server_roots,
const HttpRequest& request) {
// This is a test-only server. Ignore I/O thread restrictions.
base::ThreadRestrictions::ScopedAllowIO allow_io;
@@ -64,28 +64,31 @@ scoped_ptr<HttpResponse> HandleFileRequest(
if (query_pos != std::string::npos)
request_path = request_path.substr(0, query_pos);
- base::FilePath file_path(server_root.AppendASCII(request_path));
- std::string file_contents;
- if (!base::ReadFileToString(file_path, &file_contents))
- return scoped_ptr<HttpResponse>();
+ for (const auto& server_root : server_roots) {
+ base::FilePath file_path(server_root.AppendASCII(request_path));
+ std::string file_contents;
+ if (!base::ReadFileToString(file_path, &file_contents))
+ continue;
- base::FilePath headers_path(
- file_path.AddExtension(FILE_PATH_LITERAL("mock-http-headers")));
+ base::FilePath headers_path(
+ file_path.AddExtension(FILE_PATH_LITERAL("mock-http-headers")));
- if (base::PathExists(headers_path)) {
- std::string headers_contents;
- if (!base::ReadFileToString(headers_path, &headers_contents))
- return scoped_ptr<HttpResponse>();
+ if (base::PathExists(headers_path)) {
+ std::string headers_contents;
+ if (!base::ReadFileToString(headers_path, &headers_contents))
+ return scoped_ptr<HttpResponse>();
- scoped_ptr<CustomHttpResponse> http_response(
- new CustomHttpResponse(headers_contents, file_contents));
+ scoped_ptr<CustomHttpResponse> http_response(
+ new CustomHttpResponse(headers_contents, file_contents));
+ return http_response.Pass();
+ }
+
+ scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse);
+ http_response->set_code(HTTP_OK);
+ http_response->set_content(file_contents);
return http_response.Pass();
}
-
- scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse);
- http_response->set_code(HTTP_OK);
- http_response->set_content(file_contents);
- return http_response.Pass();
+ return scoped_ptr<HttpResponse>();
}
} // namespace
@@ -276,7 +279,14 @@ GURL EmbeddedTestServer::GetURL(
void EmbeddedTestServer::ServeFilesFromDirectory(
const base::FilePath& directory) {
- RegisterRequestHandler(base::Bind(&HandleFileRequest, directory));
+ std::vector<base::FilePath> directories;
+ directories.push_back(directory);
+ RegisterRequestHandler(base::Bind(&HandleFileRequest, directories));
+}
+
+void EmbeddedTestServer::ServeFilesFromDirectories(
+ const std::vector<base::FilePath>& directories) {
+ RegisterRequestHandler(base::Bind(&HandleFileRequest, directories));
}
void EmbeddedTestServer::RegisterRequestHandler(
« no previous file with comments | « net/test/embedded_test_server/embedded_test_server.h ('k') | net/test/embedded_test_server/embedded_test_server_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698