| 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_SERVER_HTTP_SERVER_H_ | 5 #ifndef NET_SERVER_HTTP_SERVER_H_ |
| 6 #define NET_SERVER_HTTP_SERVER_H_ | 6 #define NET_SERVER_HTTP_SERVER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" |
| 14 #include "net/socket/stream_listen_socket.h" | 14 #include "net/socket/stream_listen_socket.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 class HttpConnection; | 18 class HttpConnection; |
| 19 class HttpServerRequestInfo; | 19 class HttpServerRequestInfo; |
| 20 class HttpServerResponseInfo; |
| 20 class IPEndPoint; | 21 class IPEndPoint; |
| 21 class WebSocket; | 22 class WebSocket; |
| 22 | 23 |
| 23 class HttpServer : public StreamListenSocket::Delegate, | 24 class HttpServer : public StreamListenSocket::Delegate, |
| 24 public base::RefCountedThreadSafe<HttpServer> { | 25 public base::RefCountedThreadSafe<HttpServer> { |
| 25 public: | 26 public: |
| 26 class Delegate { | 27 class Delegate { |
| 27 public: | 28 public: |
| 28 virtual void OnHttpRequest(int connection_id, | 29 virtual void OnHttpRequest(int connection_id, |
| 29 const HttpServerRequestInfo& info) = 0; | 30 const HttpServerRequestInfo& info) = 0; |
| 30 | 31 |
| 31 virtual void OnWebSocketRequest(int connection_id, | 32 virtual void OnWebSocketRequest(int connection_id, |
| 32 const HttpServerRequestInfo& info) = 0; | 33 const HttpServerRequestInfo& info) = 0; |
| 33 | 34 |
| 34 virtual void OnWebSocketMessage(int connection_id, | 35 virtual void OnWebSocketMessage(int connection_id, |
| 35 const std::string& data) = 0; | 36 const std::string& data) = 0; |
| 36 | 37 |
| 37 virtual void OnClose(int connection_id) = 0; | 38 virtual void OnClose(int connection_id) = 0; |
| 38 | 39 |
| 39 protected: | 40 protected: |
| 40 virtual ~Delegate() {} | 41 virtual ~Delegate() {} |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 HttpServer(const StreamListenSocketFactory& socket_factory, | 44 HttpServer(const StreamListenSocketFactory& socket_factory, |
| 44 HttpServer::Delegate* delegate); | 45 HttpServer::Delegate* delegate); |
| 45 | 46 |
| 46 void AcceptWebSocket(int connection_id, | 47 void AcceptWebSocket(int connection_id, |
| 47 const HttpServerRequestInfo& request); | 48 const HttpServerRequestInfo& request); |
| 48 void SendOverWebSocket(int connection_id, const std::string& data); | 49 void SendOverWebSocket(int connection_id, const std::string& data); |
| 50 void SendResponse(int connection_id, const HttpServerResponseInfo& response); |
| 49 void Send(int connection_id, | 51 void Send(int connection_id, |
| 50 HttpStatusCode status_code, | 52 HttpStatusCode status_code, |
| 51 const std::string& data, | 53 const std::string& data, |
| 52 const std::string& mime_type); | 54 const std::string& mime_type); |
| 53 void Send200(int connection_id, | 55 void Send200(int connection_id, |
| 54 const std::string& data, | 56 const std::string& data, |
| 55 const std::string& mime_type); | 57 const std::string& mime_type); |
| 56 void Send404(int connection_id); | 58 void Send404(int connection_id); |
| 57 void Send500(int connection_id, const std::string& message); | 59 void Send500(int connection_id, const std::string& message); |
| 58 | 60 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 IdToConnectionMap id_to_connection_; | 94 IdToConnectionMap id_to_connection_; |
| 93 typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap; | 95 typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap; |
| 94 SocketToConnectionMap socket_to_connection_; | 96 SocketToConnectionMap socket_to_connection_; |
| 95 | 97 |
| 96 DISALLOW_COPY_AND_ASSIGN(HttpServer); | 98 DISALLOW_COPY_AND_ASSIGN(HttpServer); |
| 97 }; | 99 }; |
| 98 | 100 |
| 99 } // namespace net | 101 } // namespace net |
| 100 | 102 |
| 101 #endif // NET_SERVER_HTTP_SERVER_H_ | 103 #endif // NET_SERVER_HTTP_SERVER_H_ |
| OLD | NEW |