| 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_ | 
|  | 7 | 
|  | 8 #include <utility> | 
|  | 9 | 
|  | 10 #include "base/files/file_path.h" | 
|  | 11 #include "base/strings/string_split.h" | 
|  | 12 #include "net/test/embedded_test_server/embedded_test_server.h" | 
|  | 13 #include "net/test/embedded_test_server/http_request.h" | 
|  | 14 #include "net/test/embedded_test_server/http_response.h" | 
|  | 15 #include "url/gurl.h" | 
|  | 16 | 
|  | 17 namespace net { | 
|  | 18 namespace test_server { | 
|  | 19 | 
|  | 20 // This file is only meant for compatibility with testserver.py. No | 
|  | 21 // additional handlers should be added here that don't affect multiple | 
|  | 22 // distinct tests. | 
|  | 23 | 
|  | 24 using RequestQuery = std::map<std::string, std::vector<std::string>>; | 
|  | 25 | 
|  | 26 class CustomHttpResponse : public HttpResponse { | 
|  | 27  public: | 
|  | 28   CustomHttpResponse(const std::string& headers, const std::string& contents) | 
|  | 29       : headers_(headers), contents_(contents) {} | 
|  | 30 | 
|  | 31   void SendResponse(SendBytesCallback send, SendCompleteCallback done) override; | 
|  | 32 | 
|  | 33  private: | 
|  | 34   std::string headers_; | 
|  | 35   std::string contents_; | 
|  | 36 | 
|  | 37   DISALLOW_COPY_AND_ASSIGN(CustomHttpResponse); | 
|  | 38 }; | 
|  | 39 | 
|  | 40 // Return whether |request| starts with a URL path of |url|. | 
|  | 41 bool ShouldHandle(const HttpRequest& request, std::string url); | 
|  | 42 | 
|  | 43 // Parses |data| as the query of a URL and places it into a map. | 
|  | 44 RequestQuery ParseQuery(const GURL& url); | 
|  | 45 | 
|  | 46 // Returns a path that serves |original_path| with text that matches | 
|  | 47 // |text_to_replace| with the corresponding values, and then returns the | 
|  | 48 // resulting path in |replacement_path|. | 
|  | 49 void GetFilePathWithReplacements(const std::string& original_path, | 
|  | 50                                  const base::StringPairs& text_to_replace, | 
|  | 51                                  std::string* replacement_path); | 
|  | 52 | 
|  | 53 // Handles |request| by serving a file from under |server_root|. | 
|  | 54 scoped_ptr<HttpResponse> HandleFileRequest(const base::FilePath& server_root, | 
|  | 55                                            const HttpRequest& request); | 
|  | 56 | 
|  | 57 // Registers default handlers for use in tests. | 
|  | 58 void RegisterDefaultHandlers(EmbeddedTestServer* server); | 
|  | 59 | 
|  | 60 }  // namespace test_server | 
|  | 61 }  // namespace net | 
|  | 62 | 
|  | 63 #endif  // NET_TEST_EMBEDDED_TEST_SERVER_REQUEST_HELPERS_H_ | 
| OLD | NEW | 
|---|