OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_SERVER_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_SERVER_H_ |
6 #define CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_SERVER_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_SERVER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 bool InitializeAndWaitUntilReady(); | 68 bool InitializeAndWaitUntilReady(); |
69 | 69 |
70 // Shuts down the http server and waits until the shutdown is complete. | 70 // Shuts down the http server and waits until the shutdown is complete. |
71 void ShutdownAndWaitUntilComplete(); | 71 void ShutdownAndWaitUntilComplete(); |
72 | 72 |
73 // Checks if the server is started. | 73 // Checks if the server is started. |
74 bool Started() const { | 74 bool Started() const { |
75 return listen_socket_.get() != NULL; | 75 return listen_socket_.get() != NULL; |
76 } | 76 } |
77 | 77 |
78 // Provides URL to the server which is useful when general purpose provider | 78 // Returns the base URL to the server, which looks like |
79 // is registered. | 79 // http://127.0.0.1:<port>/, where <port> is the actual port number used by |
80 GURL GetBaseURL(); | 80 // the server. |
81 GURL GetBaseURL() const; | |
82 | |
83 // Returns a URL to the server based on the given relative URL, which | |
84 // should start with '/'. For example: GetURL("/path?query=foo") => | |
85 // http://127.0.0.1:<port>/path?query=foo. | |
86 GURL GetURL(const std::string& relative_url) const; | |
87 | |
88 // Returns the port number used by the server. | |
89 int port() const { return port_; } | |
81 | 90 |
82 // The most general purpose method. Any request processing can be added using | 91 // The most general purpose method. Any request processing can be added using |
83 // this method. Takes ownership of the object. The |callback| is called | 92 // this method. Takes ownership of the object. The |callback| is called |
84 // on UI thread. | 93 // on UI thread. |
85 void RegisterRequestHandler(const HandleRequestCallback& callback); | 94 void RegisterRequestHandler(const HandleRequestCallback& callback); |
86 | 95 |
87 // Used to provide the same predefined response for the requests matching | 96 // Used to provide the same predefined response for the requests matching |
88 // the |relative_path|. Should be used if any custom data, such as additional | 97 // the |relative_path|, which should start with '/'. Should be used if any |
89 // headers should be send from the server. | 98 // custom data, such as additional headers should be send from the server. |
hashimoto
2012/11/16 05:38:10
s/should be send/should be sent/
satorux1
2012/11/16 05:56:44
Done.
| |
90 GURL RegisterDefaultResponse( | 99 void RegisterDefaultResponse( |
91 const std::string& relative_path, | 100 const std::string& relative_path, |
92 const HttpResponse& default_response); | 101 const HttpResponse& default_response); |
93 | 102 |
94 // Registers a simple text response. | 103 // Registers a simple text response. |
95 GURL RegisterTextResponse( | 104 void RegisterTextResponse( |
96 const std::string& relative_path, | 105 const std::string& relative_path, |
97 const std::string& content, | 106 const std::string& content, |
98 const std::string& content_type, | 107 const std::string& content_type, |
99 const ResponseCode response_code); | 108 const ResponseCode response_code); |
100 | 109 |
101 // Registers a simple file response. The file is loaded into memory. | 110 // Registers a simple file response. The file is loaded into memory. |
102 GURL RegisterFileResponse( | 111 void RegisterFileResponse( |
103 const std::string& relative_path, | 112 const std::string& relative_path, |
104 const FilePath& file_path, | 113 const FilePath& file_path, |
105 const std::string& content_type, | 114 const std::string& content_type, |
106 const ResponseCode response_code); | 115 const ResponseCode response_code); |
107 | 116 |
108 private: | 117 private: |
109 // Initializes and starts the server. If initialization succeeds, Starts() | 118 // Initializes and starts the server. If initialization succeeds, Starts() |
110 // will return true. | 119 // will return true. |
111 void InitializeOnIOThread(); | 120 void InitializeOnIOThread(); |
112 | 121 |
(...skipping 28 matching lines...) Expand all Loading... | |
141 // Note: This should remain the last member so it'll be destroyed and | 150 // Note: This should remain the last member so it'll be destroyed and |
142 // invalidate its weak pointers before any other members are destroyed. | 151 // invalidate its weak pointers before any other members are destroyed. |
143 base::WeakPtrFactory<HttpServer> weak_factory_; | 152 base::WeakPtrFactory<HttpServer> weak_factory_; |
144 DISALLOW_COPY_AND_ASSIGN(HttpServer); | 153 DISALLOW_COPY_AND_ASSIGN(HttpServer); |
145 }; | 154 }; |
146 | 155 |
147 } // namespace test_servers | 156 } // namespace test_servers |
148 } // namespace google_apis | 157 } // namespace google_apis |
149 | 158 |
150 #endif // CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_SERVER_H_ | 159 #endif // CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_SERVER_H_ |
OLD | NEW |