| 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 class CustomHttpResponse : public HttpResponse { | 
 |  34  public: | 
 |  35   CustomHttpResponse(const std::string& headers, const std::string& contents); | 
 |  36   ~CustomHttpResponse() override; | 
 |  37  | 
 |  38   void SendResponse(const SendBytesCallback& send, | 
 |  39                     const SendCompleteCallback& done) override; | 
 |  40  | 
 |  41  private: | 
 |  42   const std::string headers_; | 
 |  43   const std::string contents_; | 
 |  44  | 
 |  45   DISALLOW_COPY_AND_ASSIGN(CustomHttpResponse); | 
 |  46 }; | 
 |  47  | 
 |  48 // Return whether |request| starts with a URL path of |url|. | 
 |  49 bool ShouldHandle(const HttpRequest& request, const std::string& prefix_path); | 
 |  50  | 
 |  51 // Calls |handler| if the |request| URL starts with |prefix|. | 
 |  52 scoped_ptr<HttpResponse> HandlePrefixedRequest( | 
 |  53     const std::string& prefix, | 
 |  54     const EmbeddedTestServer::HandleRequestCallback& handler, | 
 |  55     const HttpRequest& request); | 
 |  56  | 
 |  57 // Parses |url| to get the query and places it into a map. | 
 |  58 RequestQuery ParseQuery(const GURL& url); | 
 |  59  | 
 |  60 // Returns a path that serves the contents of the file at |original_path| | 
 |  61 // with all the text matching the elements of |text_to_replace| replaced | 
 |  62 // with the corresponding values. The path is returned in |replacement_path|. | 
 |  63 // The result path is only usable by HandleFileRequest which will perform the | 
 |  64 // actual replacements of the file contents. | 
 |  65 // TODO(svaldez): Modify to return |replacement_path| instead of passing by | 
 |  66 // reference. | 
 |  67 void GetFilePathWithReplacements(const std::string& original_path, | 
 |  68                                  const base::StringPairs& text_to_replace, | 
 |  69                                  std::string* replacement_path); | 
 |  70  | 
 |  71 // Handles |request| by serving a file from under |server_root|. | 
 |  72 scoped_ptr<HttpResponse> HandleFileRequest(const base::FilePath& server_root, | 
 |  73                                            const HttpRequest& request); | 
 |  74  | 
 |  75 }  // namespace test_server | 
 |  76 }  // namespace net | 
 |  77  | 
 |  78 #endif  // NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HANDLER_UTIL_H_ | 
| OLD | NEW |