Chromium Code Reviews| 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_HELPERS_H_ | |
| 6 #define NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HELPERS_H_ | |
|
mmenke
2015/10/21 20:21:37
nit: "_util.h" is a more common suffix for a file
svaldez
2015/10/21 21:22:29
Done.
| |
| 7 | |
| 8 #include <utility> | |
|
mmenke
2015/10/21 20:21:37
<string>, <map>, and <vector> all seem to be neede
mmenke
2015/10/21 20:21:37
What's this needed for?
svaldez
2015/10/21 21:22:29
Done.
svaldez
2015/10/21 21:22:29
Done.
| |
| 9 | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/macros.h" | |
|
mmenke
2015/10/21 20:21:37
base/memory/scoped_ptr
svaldez
2015/10/21 21:22:29
Done.
| |
| 12 #include "base/strings/string_split.h" | |
| 13 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 14 #include "net/test/embedded_test_server/http_request.h" | |
| 15 #include "net/test/embedded_test_server/http_response.h" | |
| 16 #include "url/gurl.h" | |
|
mmenke
2015/10/21 20:21:37
HttpRequest and GURL can be forward declared, and
svaldez
2015/10/21 21:22:29
Done.
| |
| 17 | |
| 18 namespace net { | |
| 19 namespace test_server { | |
| 20 | |
| 21 // This file is only meant for compatibility with testserver.py. No | |
| 22 // additional handlers should be added here that don't affect multiple | |
| 23 // distinct tests. | |
| 24 | |
| 25 using RequestQuery = std::map<std::string, std::vector<std::string>>; | |
| 26 | |
| 27 class CustomHttpResponse : public HttpResponse { | |
| 28 public: | |
| 29 CustomHttpResponse(const std::string& headers, const std::string& contents); | |
| 30 ~CustomHttpResponse() override{}; | |
|
mmenke
2015/10/21 20:21:37
nit: de-inline this.
svaldez
2015/10/21 21:22:29
Done.
| |
| 31 | |
| 32 void SendResponse(const SendBytesCallback& send, | |
| 33 const SendCompleteCallback& done) override; | |
| 34 | |
| 35 private: | |
| 36 const std::string headers_; | |
| 37 const std::string contents_; | |
| 38 | |
| 39 DISALLOW_COPY_AND_ASSIGN(CustomHttpResponse); | |
| 40 }; | |
| 41 | |
| 42 // Return whether |request| starts with a URL path of |url|. | |
| 43 bool ShouldHandle(const HttpRequest& request, const std::string& prefix_path); | |
| 44 | |
| 45 // Calls |handler| if the |request| URL starts with |prefix|. | |
| 46 scoped_ptr<HttpResponse> HandlePrefixedRequest( | |
| 47 const std::string& prefix, | |
| 48 const EmbeddedTestServer::HandleRequestCallback& handler, | |
| 49 const HttpRequest& request); | |
| 50 | |
| 51 // Parses |url| to get the query and places it into a map. | |
| 52 RequestQuery ParseQuery(const GURL& url); | |
| 53 | |
| 54 // Returns a path that serves the contents of the file at |original_path| | |
| 55 // with all the text matching the elements of |text_to_replace| replaced | |
| 56 // with the corresponding values. The path is returned in |replacement_path|. | |
| 57 // HandleFileRequest will handle the resulting path. | |
| 58 void GetFilePathWithReplacements(const std::string& original_path, | |
| 59 const base::StringPairs& text_to_replace, | |
| 60 std::string* replacement_path); | |
|
mmenke
2015/10/21 20:21:37
There are two problems here:
1) It's not clear t
mmenke
2015/10/21 20:21:37
Suggest just returning a string - we're doing a fi
svaldez
2015/10/21 21:22:29
Done.
svaldez
2015/10/21 21:22:29
Adding a TODO, since this is currently trying to m
| |
| 61 | |
| 62 // Handles |request| by serving a file from under |server_root|. | |
| 63 scoped_ptr<HttpResponse> HandleFileRequest(const base::FilePath& server_root, | |
| 64 const HttpRequest& request); | |
| 65 | |
| 66 } // namespace test_server | |
| 67 } // namespace net | |
| 68 | |
| 69 #endif // NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HELPERS_H_ | |
| OLD | NEW |