Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: net/tools/fetch/http_listen_socket.h

Issue 99333: A utility driver for doing client/server HTTP transaction... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/tools/fetch/fetch_server.cc ('k') | net/tools/fetch/http_listen_socket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/fetch/http_listen_socket.h
===================================================================
--- net/tools/fetch/http_listen_socket.h (revision 0)
+++ net/tools/fetch/http_listen_socket.h (revision 0)
@@ -0,0 +1,55 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_
+#define NET_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_
+
+#include "base/message_loop.h"
+#include "net/base/listen_socket.h"
+
+class HttpServerRequestInfo;
+class HttpServerResponseInfo;
+
+// Implements a simple HTTP listen socket on top of the raw socket interface.
+class HttpListenSocket : public ListenSocket,
+ public ListenSocket::ListenSocketDelegate {
+public:
+ class Delegate {
+ public:
+ virtual void OnRequest(HttpListenSocket* connection,
+ HttpServerRequestInfo* info) = 0;
+ };
+
+ static HttpListenSocket* Listen(const std::string& ip, int port,
+ HttpListenSocket::Delegate* delegate);
+ virtual ~HttpListenSocket();
+
+ void Listen() { ListenSocket::Listen(); }
+ virtual void Accept();
+
+ // Send a server response.
+ // TODO(mbelshe): make this capable of non-ascii data.
+ void Respond(HttpServerResponseInfo* info, std::string& data);
+
+ // ListenSocketDelegate
+ virtual void DidAccept(ListenSocket* server, ListenSocket* connection);
+ virtual void DidRead(ListenSocket* connection, const std::string& data);
+ virtual void DidClose(ListenSocket* sock);
+
+private:
+ static const int kReadBufSize = 16 * 1024;
+ HttpListenSocket(SOCKET s, HttpListenSocket::Delegate* del);
+
+ // Expects the raw data to be stored in recv_data_. If parsing is successful,
+ // will remove the data parsed from recv_data_, leaving only the unused
+ // recv data.
+ HttpServerRequestInfo* ParseHeaders();
+
+ HttpListenSocket::Delegate* delegate_;
+ std::string recv_data_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(HttpListenSocket);
+};
+
+#endif // NET_BASE_TOOLS_HTTP_LISTEN_SOCKET_H_
« no previous file with comments | « net/tools/fetch/fetch_server.cc ('k') | net/tools/fetch/http_listen_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698