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 12 matching lines...) Expand all Loading... | |
23 class HttpListenSocket: public net::TCPListenSocket { | 23 class HttpListenSocket: public net::TCPListenSocket { |
24 public: | 24 public: |
25 HttpListenSocket(const SocketDescriptor socket_descriptor, | 25 HttpListenSocket(const SocketDescriptor socket_descriptor, |
26 net::StreamListenSocket::Delegate* delegate); | 26 net::StreamListenSocket::Delegate* delegate); |
27 virtual void Listen(); | 27 virtual void Listen(); |
28 | 28 |
29 private: | 29 private: |
30 virtual ~HttpListenSocket(); | 30 virtual ~HttpListenSocket(); |
31 }; | 31 }; |
32 | 32 |
33 // Class providing a HTTP server for testing purpose. This is a basic server | 33 // Class providing a HTTP server for testing purpose. This is a basic server |
mtomasz
2012/12/03 23:08:24
nit: Please update this comment.
satorux1
2012/12/03 23:48:14
Good catch. Done!
| |
34 // providing only an essential subset of HTTP/1.1 protocol. Especially, | 34 // providing only an essential subset of HTTP/1.1 protocol. Especially, |
35 // it assumes that the request syntax is correct. It *does not* support | 35 // it assumes that the request syntax is correct. It *does not* support |
36 // a Chunked Transfer Encoding. | 36 // a Chunked Transfer Encoding. |
37 // | 37 // |
38 // The common use case is below: | 38 // The common use case is below: |
39 // | 39 // |
40 // scoped_ptr<HttpServer> test_server_; | 40 // scoped_ptr<HttpServer> test_server_; |
41 // GURL hello_world_url_; | 41 // GURL hello_world_url_; |
42 // GURL file_url_; | 42 // GURL file_url_; |
43 // (...) | 43 // (...) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 GURL GetURL(const std::string& relative_url) const; | 86 GURL GetURL(const std::string& relative_url) const; |
87 | 87 |
88 // Returns the port number used by the server. | 88 // Returns the port number used by the server. |
89 int port() const { return port_; } | 89 int port() const { return port_; } |
90 | 90 |
91 // 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 |
92 // this method. Takes ownership of the object. The |callback| is called | 92 // this method. Takes ownership of the object. The |callback| is called |
93 // on UI thread. | 93 // on UI thread. |
94 void RegisterRequestHandler(const HandleRequestCallback& callback); | 94 void RegisterRequestHandler(const HandleRequestCallback& callback); |
95 | 95 |
96 // Used to provide the same predefined response for the requests matching | |
97 // the |relative_path|, which should start with '/'. Should be used if any | |
98 // custom data, such as additional headers should be sent from the server. | |
99 void RegisterDefaultResponse( | |
100 const std::string& relative_path, | |
101 const HttpResponse& default_response); | |
102 | |
103 // Registers a simple text response. | |
104 void RegisterTextResponse( | |
105 const std::string& relative_path, | |
106 const std::string& content, | |
107 const std::string& content_type, | |
108 const ResponseCode response_code); | |
109 | |
110 // Registers a simple file response. The file is loaded into memory. | |
111 void RegisterFileResponse( | |
112 const std::string& relative_path, | |
113 const FilePath& file_path, | |
114 const std::string& content_type, | |
115 const ResponseCode response_code); | |
116 | |
117 private: | 96 private: |
118 // Initializes and starts the server. If initialization succeeds, Starts() | 97 // Initializes and starts the server. If initialization succeeds, Starts() |
119 // will return true. | 98 // will return true. |
120 void InitializeOnIOThread(); | 99 void InitializeOnIOThread(); |
121 | 100 |
122 // Shuts down the server. | 101 // Shuts down the server. |
123 void ShutdownOnIOThread(); | 102 void ShutdownOnIOThread(); |
124 | 103 |
125 // Handles a request when it is parsed. It passes the request to registed | 104 // Handles a request when it is parsed. It passes the request to registed |
126 // request handlers and sends a http response. | 105 // request handlers and sends a http response. |
(...skipping 23 matching lines...) Expand all Loading... | |
150 // Note: This should remain the last member so it'll be destroyed and | 129 // Note: This should remain the last member so it'll be destroyed and |
151 // invalidate its weak pointers before any other members are destroyed. | 130 // invalidate its weak pointers before any other members are destroyed. |
152 base::WeakPtrFactory<HttpServer> weak_factory_; | 131 base::WeakPtrFactory<HttpServer> weak_factory_; |
153 DISALLOW_COPY_AND_ASSIGN(HttpServer); | 132 DISALLOW_COPY_AND_ASSIGN(HttpServer); |
154 }; | 133 }; |
155 | 134 |
156 } // namespace test_servers | 135 } // namespace test_servers |
157 } // namespace google_apis | 136 } // namespace google_apis |
158 | 137 |
159 #endif // CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_SERVER_H_ | 138 #endif // CHROME_BROWSER_GOOGLE_APIS_TEST_SERVER_HTTP_SERVER_H_ |
OLD | NEW |