#ifndef __HttpThread_h_ #define __HttpThread_h_ #include "../shared/ThreadClass.h" #include "../shared/Messages.h" #include "SCGI.h" class HttpRequest; class HttpResponsePrep { public: virtual void prepairHttpResponse(HttpRequest *request, ScgiToServer &response) =0; virtual ~HttpResponsePrep() {} }; class HttpRequest : public Request { private: // Every request should generate exactly one response. bool _responseSent; void autoCompress(ScgiToServer &response); public: ScgiFromServer fromServer; HttpRequest(SocketInfo *socketInfo) : Request(socketInfo), _responseSent(false), defaultResponse(NULL) { } ~HttpRequest(); // This could possibly modify the response. For example, it might // automatically compress the data like ob_gzhandler. This automatically // deletes the socket after sending the response. void sendResponse(ScgiToServer &response); void send404Response(); // If we delete the request before sending a respond, the request // automatically sends a response. If this is not null, it provides // the response. HttpResponsePrep *defaultResponse; }; class HttpListener { public: virtual void onHttpRequest(HttpRequest *httpRequest) =0; virtual ~HttpListener() { } }; class HttpThread : private ThreadClass { private: HttpListener *const _httpListener; typedef std::map< class SocketInfo *, HttpRequest * > PendingRequests; PendingRequests _pendingRequests; enum { mtNewInput, mtTimeout, mtQuit }; RequestQueue _incomingRequests; void cleanUp(class SocketInfo *socket, std::string const &reason, bool andDelete = true); protected: void threadFunction(); public: HttpThread(HttpListener *httpListener, std::string name = "HttpThread"); ~HttpThread(); // These are for the thread which sends data to us. RequestListener *getInput() { return &_incomingRequests; } int getInputCallbackId() { return mtNewInput; } }; #endif