| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "net/base/listen_socket.h" | 14 #include "net/base/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 WebSocket; | 20 class WebSocket; |
| 21 | 21 |
| 22 class HttpServer : public ListenSocket::ListenSocketDelegate, | 22 class HttpServer : public StreamListenSocket::Delegate, |
| 23 public base::RefCountedThreadSafe<HttpServer> { | 23 public base::RefCountedThreadSafe<HttpServer> { |
| 24 public: | 24 public: |
| 25 class Delegate { | 25 class Delegate { |
| 26 public: | 26 public: |
| 27 virtual void OnHttpRequest(int connection_id, | 27 virtual void OnHttpRequest(int connection_id, |
| 28 const HttpServerRequestInfo& info) = 0; | 28 const HttpServerRequestInfo& info) = 0; |
| 29 | 29 |
| 30 virtual void OnWebSocketRequest(int connection_id, | 30 virtual void OnWebSocketRequest(int connection_id, |
| 31 const HttpServerRequestInfo& info) = 0; | 31 const HttpServerRequestInfo& info) = 0; |
| 32 | 32 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 const std::string& data, | 50 const std::string& data, |
| 51 const std::string& mime_type); | 51 const std::string& mime_type); |
| 52 void Send404(int connection_id); | 52 void Send404(int connection_id); |
| 53 void Send500(int connection_id, const std::string& message); | 53 void Send500(int connection_id, const std::string& message); |
| 54 void Close(int connection_id); | 54 void Close(int connection_id); |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 friend class base::RefCountedThreadSafe<HttpServer>; | 57 friend class base::RefCountedThreadSafe<HttpServer>; |
| 58 friend class HttpConnection; | 58 friend class HttpConnection; |
| 59 | 59 |
| 60 // ListenSocketDelegate | 60 // StreamListenSocket::Delegate |
| 61 virtual void DidAccept(ListenSocket* server, ListenSocket* socket) OVERRIDE; | 61 virtual void DidAccept(StreamListenSocket* server, |
| 62 virtual void DidRead(ListenSocket* socket, | 62 StreamListenSocket* socket) OVERRIDE; |
| 63 virtual void DidRead(StreamListenSocket* socket, |
| 63 const char* data, | 64 const char* data, |
| 64 int len) OVERRIDE; | 65 int len) OVERRIDE; |
| 65 virtual void DidClose(ListenSocket* socket) OVERRIDE; | 66 virtual void DidClose(StreamListenSocket* socket) OVERRIDE; |
| 66 | 67 |
| 67 // Expects the raw data to be stored in recv_data_. If parsing is successful, | 68 // Expects the raw data to be stored in recv_data_. If parsing is successful, |
| 68 // will remove the data parsed from recv_data_, leaving only the unused | 69 // will remove the data parsed from recv_data_, leaving only the unused |
| 69 // recv data. | 70 // recv data. |
| 70 bool ParseHeaders(HttpConnection* connection, | 71 bool ParseHeaders(HttpConnection* connection, |
| 71 HttpServerRequestInfo* info, | 72 HttpServerRequestInfo* info, |
| 72 size_t* pos); | 73 size_t* pos); |
| 73 | 74 |
| 74 HttpConnection* FindConnection(int connection_id); | 75 HttpConnection* FindConnection(int connection_id); |
| 75 HttpConnection* FindConnection(ListenSocket* socket); | 76 HttpConnection* FindConnection(StreamListenSocket* socket); |
| 76 | 77 |
| 77 HttpServer::Delegate* delegate_; | 78 HttpServer::Delegate* delegate_; |
| 78 scoped_refptr<ListenSocket> server_; | 79 scoped_refptr<StreamListenSocket> server_; |
| 79 typedef std::map<int, HttpConnection*> IdToConnectionMap; | 80 typedef std::map<int, HttpConnection*> IdToConnectionMap; |
| 80 IdToConnectionMap id_to_connection_; | 81 IdToConnectionMap id_to_connection_; |
| 81 typedef std::map<ListenSocket*, HttpConnection*> SocketToConnectionMap; | 82 typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap; |
| 82 SocketToConnectionMap socket_to_connection_; | 83 SocketToConnectionMap socket_to_connection_; |
| 83 | 84 |
| 84 DISALLOW_COPY_AND_ASSIGN(HttpServer); | 85 DISALLOW_COPY_AND_ASSIGN(HttpServer); |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 } // namespace net | 88 } // namespace net |
| 88 | 89 |
| 89 #endif // NET_SERVER_HTTP_SERVER_H_ | 90 #endif // NET_SERVER_HTTP_SERVER_H_ |
| OLD | NEW |