| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HANDLER_UTIL_H_ | |
| 6 #define NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HANDLER_UTIL_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/strings/string_split.h" | |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 17 #include "net/test/embedded_test_server/http_response.h" | |
| 18 | |
| 19 namespace url { | |
| 20 class GURL; | |
| 21 } | |
| 22 | |
| 23 namespace net { | |
| 24 namespace test_server { | |
| 25 struct HttpRequest; | |
| 26 | |
| 27 // This file is only meant for compatibility with testserver.py. No | |
| 28 // additional handlers should be added here that don't affect multiple | |
| 29 // distinct tests. | |
| 30 | |
| 31 using RequestQuery = std::map<std::string, std::vector<std::string>>; | |
| 32 | |
| 33 // Return whether |request| starts with a URL path of |url|. | |
| 34 bool ShouldHandle(const HttpRequest& request, const std::string& prefix_path); | |
| 35 | |
| 36 // Calls |handler| if the |request| URL starts with |prefix|. | |
| 37 scoped_ptr<HttpResponse> HandlePrefixedRequest( | |
| 38 const std::string& prefix, | |
| 39 const EmbeddedTestServer::HandleRequestCallback& handler, | |
| 40 const HttpRequest& request); | |
| 41 | |
| 42 // Parses |url| to get the query and places it into a map. | |
| 43 RequestQuery ParseQuery(const GURL& url); | |
| 44 | |
| 45 // Returns a path that serves the contents of the file at |original_path| | |
| 46 // with all the text matching the elements of |text_to_replace| replaced | |
| 47 // with the corresponding values. The path is returned in |replacement_path|. | |
| 48 // The result path is only usable by HandleFileRequest which will perform the | |
| 49 // actual replacements of the file contents. | |
| 50 // TODO(svaldez): Modify to return |replacement_path| instead of passing by | |
| 51 // reference. | |
| 52 void GetFilePathWithReplacements(const std::string& original_path, | |
| 53 const base::StringPairs& text_to_replace, | |
| 54 std::string* replacement_path); | |
| 55 | |
| 56 // Handles |request| by serving a file from under |server_root|. | |
| 57 scoped_ptr<HttpResponse> HandleFileRequest(const base::FilePath& server_root, | |
| 58 const HttpRequest& request); | |
| 59 | |
| 60 } // namespace test_server | |
| 61 } // namespace net | |
| 62 | |
| 63 #endif // NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HANDLER_UTIL_H_ | |
| OLD | NEW |