| 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 NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ | 5 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ |
| 6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ | 6 #define NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
| 23 #include "crypto/rsa_private_key.h" | 23 #include "crypto/rsa_private_key.h" |
| 24 #include "net/base/address_list.h" | 24 #include "net/base/address_list.h" |
| 25 #include "net/base/host_port_pair.h" | 25 #include "net/base/host_port_pair.h" |
| 26 #include "net/base/ip_endpoint.h" | 26 #include "net/base/ip_endpoint.h" |
| 27 #include "net/cert/x509_certificate.h" | 27 #include "net/cert/x509_certificate.h" |
| 28 #include "net/socket/ssl_server_socket.h" |
| 28 #include "net/socket/stream_socket.h" | 29 #include "net/socket/stream_socket.h" |
| 29 #include "net/socket/tcp_server_socket.h" | 30 #include "net/socket/tcp_server_socket.h" |
| 30 #include "net/ssl/ssl_server_config.h" | 31 #include "net/ssl/ssl_server_config.h" |
| 31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 32 | 33 |
| 33 namespace net { | 34 namespace net { |
| 34 | 35 |
| 35 class StreamSocket; | 36 class StreamSocket; |
| 36 class TCPServerSocket; | 37 class TCPServerSocket; |
| 37 | 38 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 bool HandleReadResult(HttpConnection* connection, int rv); | 237 bool HandleReadResult(HttpConnection* connection, int rv); |
| 237 | 238 |
| 238 // Closes and removes the connection upon error or completion. | 239 // Closes and removes the connection upon error or completion. |
| 239 void DidClose(HttpConnection* connection); | 240 void DidClose(HttpConnection* connection); |
| 240 | 241 |
| 241 // Handles a request when it is parsed. It passes the request to registered | 242 // Handles a request when it is parsed. It passes the request to registered |
| 242 // request handlers and sends a http response. | 243 // request handlers and sends a http response. |
| 243 void HandleRequest(HttpConnection* connection, | 244 void HandleRequest(HttpConnection* connection, |
| 244 scoped_ptr<HttpRequest> request); | 245 scoped_ptr<HttpRequest> request); |
| 245 | 246 |
| 247 // Initializes the SSLServerContext so that SSLServerSocket connections may |
| 248 // share the same cache |
| 249 void InitializeSSLServerContext(); |
| 250 |
| 246 HttpConnection* FindConnection(StreamSocket* socket); | 251 HttpConnection* FindConnection(StreamSocket* socket); |
| 247 | 252 |
| 248 // Posts a task to the |io_thread_| and waits for a reply. | 253 // Posts a task to the |io_thread_| and waits for a reply. |
| 249 bool PostTaskToIOThreadAndWait( | 254 bool PostTaskToIOThreadAndWait( |
| 250 const base::Closure& closure) WARN_UNUSED_RESULT; | 255 const base::Closure& closure) WARN_UNUSED_RESULT; |
| 251 | 256 |
| 252 const bool is_using_ssl_; | 257 const bool is_using_ssl_; |
| 253 | 258 |
| 254 scoped_ptr<base::Thread> io_thread_; | 259 scoped_ptr<base::Thread> io_thread_; |
| 255 | 260 |
| 256 scoped_ptr<TCPServerSocket> listen_socket_; | 261 scoped_ptr<TCPServerSocket> listen_socket_; |
| 257 scoped_ptr<StreamSocket> accepted_socket_; | 262 scoped_ptr<StreamSocket> accepted_socket_; |
| 258 | 263 |
| 259 EmbeddedTestServerConnectionListener* connection_listener_; | 264 EmbeddedTestServerConnectionListener* connection_listener_; |
| 260 uint16_t port_; | 265 uint16_t port_; |
| 261 GURL base_url_; | 266 GURL base_url_; |
| 262 IPEndPoint local_endpoint_; | 267 IPEndPoint local_endpoint_; |
| 263 | 268 |
| 264 // Owns the HttpConnection objects. | 269 // Owns the HttpConnection objects. |
| 265 std::map<StreamSocket*, HttpConnection*> connections_; | 270 std::map<StreamSocket*, HttpConnection*> connections_; |
| 266 | 271 |
| 267 // Vector of registered and default request handlers. | 272 // Vector of registered and default request handlers. |
| 268 std::vector<HandleRequestCallback> request_handlers_; | 273 std::vector<HandleRequestCallback> request_handlers_; |
| 269 std::vector<HandleRequestCallback> default_request_handlers_; | 274 std::vector<HandleRequestCallback> default_request_handlers_; |
| 270 | 275 |
| 271 base::ThreadChecker thread_checker_; | 276 base::ThreadChecker thread_checker_; |
| 272 | 277 |
| 273 net::SSLServerConfig ssl_config_; | 278 net::SSLServerConfig ssl_config_; |
| 274 ServerCertificate cert_; | 279 ServerCertificate cert_; |
| 280 scoped_ptr<SSLServerContext> context_; |
| 275 | 281 |
| 276 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_; | 282 base::WeakPtrFactory<EmbeddedTestServer> weak_factory_; |
| 277 | 283 |
| 278 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); | 284 DISALLOW_COPY_AND_ASSIGN(EmbeddedTestServer); |
| 279 }; | 285 }; |
| 280 | 286 |
| 281 } // namespace test_server | 287 } // namespace test_server |
| 282 | 288 |
| 283 // TODO(svaldez): Refactor EmbeddedTestServer to be in the net namespace. | 289 // TODO(svaldez): Refactor EmbeddedTestServer to be in the net namespace. |
| 284 using test_server::EmbeddedTestServer; | 290 using test_server::EmbeddedTestServer; |
| 285 | 291 |
| 286 } // namespace net | 292 } // namespace net |
| 287 | 293 |
| 288 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ | 294 #endif // NET_TEST_EMBEDDED_TEST_SERVER_EMBEDDED_TEST_SERVER_H_ |
| OLD | NEW |