/* */ #ifndef D_HTTP_SERVER_H #define D_HTTP_SERVER_H #include "common.h" #include #include #include #include "SharedHandle.h" #include "SocketBuffer.h" namespace aria2 { class SocketCore; class HttpHeader; class HttpHeaderProcessor; class DownloadEngine; class SocketRecvBuffer; class HttpServer { private: SharedHandle socket_; SharedHandle socketRecvBuffer_; SocketBuffer socketBuffer_; DownloadEngine* e_; SharedHandle headerProcessor_; SharedHandle lastRequestHeader_; uint64_t lastContentLength_; std::stringstream lastBody_; bool keepAlive_; bool gzip_; std::string username_; std::string password_; bool acceptsPersistentConnection_; bool acceptsGZip_; std::string allowOrigin_; public: HttpServer(const SharedHandle& socket, DownloadEngine* e); ~HttpServer(); SharedHandle receiveRequest(); bool receiveBody(); std::string getBody() const; const std::string& getMethod() const; const std::string& getRequestPath() const; void feedResponse(std::string& text, const std::string& contentType); void feedResponse(const std::string& status, const std::string& headers, std::string& text, const std::string& contentType); bool authenticate(); void setUsernamePassword (const std::string& username, const std::string& password); ssize_t sendResponse(); bool sendBufferIsEmpty() const; bool supportsPersistentConnection() const { return keepAlive_ && acceptsPersistentConnection_; } bool supportsGZip() const { return gzip_ && acceptsGZip_; } void enableKeepAlive() { keepAlive_ = true; } void disableKeepAlive() { keepAlive_ = false; } void enableGZip() { gzip_ = true; } void disableGZip() { gzip_ = false; } uint64_t getContentLength() const { return lastContentLength_; } const SharedHandle& getSocketRecvBuffer() const { return socketRecvBuffer_; } void setAllowOrigin(const std::string& allowOrigin) { allowOrigin_ = allowOrigin; } }; } // namespace aria2 #endif // D_HTTP_SERVER_H