From 7100b1b9ca10f8bd940ff436b2a16f91d34d5429 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 14 Jul 2012 18:59:56 +0900 Subject: Parse HTTP RPC request on the fly without buffering --- src/HttpServer.h | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'src/HttpServer.h') diff --git a/src/HttpServer.h b/src/HttpServer.h index d16916a8..995102a0 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -51,7 +51,17 @@ class HttpHeader; class HttpHeaderProcessor; class DownloadEngine; class SocketRecvBuffer; +class DiskWriter; +enum RequestType { + RPC_TYPE_NONE, + RPC_TYPE_XML, + RPC_TYPE_JSON, + RPC_TYPE_JSONP +}; + +// HTTP server class handling RPC request from the client. It is not +// intended to be a generic HTTP server. class HttpServer { private: SharedHandle socket_; @@ -61,7 +71,11 @@ private: SharedHandle headerProcessor_; SharedHandle lastRequestHeader_; int64_t lastContentLength_; - std::stringstream lastBody_; + // How many bytes are consumed. The total number of bytes is + // lastContentLength_. + int64_t bodyConsumed_; + RequestType reqType_; + SharedHandle lastBody_; bool keepAlive_; bool gzip_; std::string username_; @@ -78,12 +92,25 @@ public: bool receiveBody(); - std::string getBody() const; - const std::string& getMethod() const; const std::string& getRequestPath() const; + int setupResponseRecv(); + + std::string createPath() const; + + std::string createQuery() const; + + const SharedHandle& getBody() const + { + return lastBody_; + } + + RequestType getRequestType() const + { + return reqType_; + } void feedResponse(std::string& text, const std::string& contentType); -- cgit