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" | |
14 #include "net/socket/stream_listen_socket.h" | 13 #include "net/socket/stream_listen_socket.h" |
15 | 14 |
16 namespace net { | 15 namespace net { |
17 | 16 |
18 class HttpConnection; | 17 class HttpConnection; |
19 class HttpServerRequestInfo; | 18 class HttpServerRequestInfo; |
| 19 class HttpServerResponseInfo; |
20 class IPEndPoint; | 20 class IPEndPoint; |
21 class WebSocket; | 21 class WebSocket; |
22 | 22 |
23 class HttpServer : public StreamListenSocket::Delegate, | 23 class HttpServer : public StreamListenSocket::Delegate, |
24 public base::RefCountedThreadSafe<HttpServer> { | 24 public base::RefCountedThreadSafe<HttpServer> { |
25 public: | 25 public: |
26 class Delegate { | 26 class Delegate { |
27 public: | 27 public: |
28 virtual void OnHttpRequest(int connection_id, | 28 virtual void OnHttpRequest(int connection_id, |
29 const HttpServerRequestInfo& info) = 0; | 29 const HttpServerRequestInfo& info) = 0; |
30 | 30 |
31 virtual void OnWebSocketRequest(int connection_id, | 31 virtual void OnWebSocketRequest(int connection_id, |
32 const HttpServerRequestInfo& info) = 0; | 32 const HttpServerRequestInfo& info) = 0; |
33 | 33 |
34 virtual void OnWebSocketMessage(int connection_id, | 34 virtual void OnWebSocketMessage(int connection_id, |
35 const std::string& data) = 0; | 35 const std::string& data) = 0; |
36 | 36 |
37 virtual void OnClose(int connection_id) = 0; | 37 virtual void OnClose(int connection_id) = 0; |
38 | 38 |
39 protected: | 39 protected: |
40 virtual ~Delegate() {} | 40 virtual ~Delegate() {} |
41 }; | 41 }; |
42 | 42 |
43 HttpServer(const StreamListenSocketFactory& socket_factory, | 43 HttpServer(const StreamListenSocketFactory& socket_factory, |
44 HttpServer::Delegate* delegate); | 44 HttpServer::Delegate* delegate); |
45 | 45 |
46 void AcceptWebSocket(int connection_id, | 46 void AcceptWebSocket(int connection_id, |
47 const HttpServerRequestInfo& request); | 47 const HttpServerRequestInfo& request); |
48 void SendOverWebSocket(int connection_id, const std::string& data); | 48 void SendOverWebSocket(int connection_id, const std::string& data); |
49 void Send(int connection_id, | 49 void Send(int connection_id, const HttpServerResponseInfo& response); |
50 HttpStatusCode status_code, | |
51 const std::string& data, | |
52 const std::string& mime_type); | |
53 void Send200(int connection_id, | 50 void Send200(int connection_id, |
54 const std::string& data, | 51 const std::string& data, |
55 const std::string& mime_type); | 52 const std::string& mime_type); |
56 void Send404(int connection_id); | 53 void Send404(int connection_id); |
57 void Send500(int connection_id, const std::string& message); | 54 void Send500(int connection_id, const std::string& message); |
58 | 55 |
59 void Close(int connection_id); | 56 void Close(int connection_id); |
60 | 57 |
61 // Copies the local address to |address|. Returns a network error code. | 58 // Copies the local address to |address|. Returns a network error code. |
62 int GetLocalAddress(IPEndPoint* address); | 59 int GetLocalAddress(IPEndPoint* address); |
(...skipping 29 matching lines...) Expand all Loading... |
92 IdToConnectionMap id_to_connection_; | 89 IdToConnectionMap id_to_connection_; |
93 typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap; | 90 typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap; |
94 SocketToConnectionMap socket_to_connection_; | 91 SocketToConnectionMap socket_to_connection_; |
95 | 92 |
96 DISALLOW_COPY_AND_ASSIGN(HttpServer); | 93 DISALLOW_COPY_AND_ASSIGN(HttpServer); |
97 }; | 94 }; |
98 | 95 |
99 } // namespace net | 96 } // namespace net |
100 | 97 |
101 #endif // NET_SERVER_HTTP_SERVER_H_ | 98 #endif // NET_SERVER_HTTP_SERVER_H_ |
OLD | NEW |