OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_ | 5 #ifndef NET_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_ |
6 #define NET_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_ | 6 #define NET_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_ |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "net/base/listen_socket.h" | 9 #include "net/base/listen_socket.h" |
10 | 10 |
11 class HttpServerRequestInfo; | 11 class HttpServerRequestInfo; |
12 class HttpServerResponseInfo; | 12 class HttpServerResponseInfo; |
13 | 13 |
14 // Implements a simple HTTP listen socket on top of the raw socket interface. | 14 // Implements a simple HTTP listen socket on top of the raw socket interface. |
15 class HttpListenSocket : public ListenSocket, | 15 class HttpListenSocket : public ListenSocket, |
16 public ListenSocket::ListenSocketDelegate { | 16 public ListenSocket::ListenSocketDelegate { |
17 public: | 17 public: |
18 class Delegate { | 18 class Delegate { |
19 public: | 19 public: |
20 virtual void OnRequest(HttpListenSocket* connection, | 20 virtual void OnRequest(HttpListenSocket* connection, |
21 HttpServerRequestInfo* info) = 0; | 21 HttpServerRequestInfo* info) = 0; |
22 | |
23 protected: | |
24 ~Delegate() {} | |
25 }; | 22 }; |
26 | 23 |
27 static HttpListenSocket* Listen(const std::string& ip, int port, | 24 static HttpListenSocket* Listen(const std::string& ip, int port, |
28 HttpListenSocket::Delegate* delegate); | 25 HttpListenSocket::Delegate* delegate); |
29 virtual ~HttpListenSocket(); | 26 virtual ~HttpListenSocket(); |
30 | 27 |
31 void Listen() { ListenSocket::Listen(); } | 28 void Listen() { ListenSocket::Listen(); } |
32 virtual void Accept(); | 29 virtual void Accept(); |
33 | 30 |
34 // Send a server response. | 31 // Send a server response. |
(...skipping 14 matching lines...) Expand all Loading... |
49 // recv data. | 46 // recv data. |
50 HttpServerRequestInfo* ParseHeaders(); | 47 HttpServerRequestInfo* ParseHeaders(); |
51 | 48 |
52 HttpListenSocket::Delegate* delegate_; | 49 HttpListenSocket::Delegate* delegate_; |
53 std::string recv_data_; | 50 std::string recv_data_; |
54 | 51 |
55 DISALLOW_EVIL_CONSTRUCTORS(HttpListenSocket); | 52 DISALLOW_EVIL_CONSTRUCTORS(HttpListenSocket); |
56 }; | 53 }; |
57 | 54 |
58 #endif // NET_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_ | 55 #endif // NET_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_ |
OLD | NEW |