/* */ #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 Logger; class HttpServer { private: SharedHandle socket_; SocketBuffer socketBuffer_; DownloadEngine* e_; SharedHandle headerProcessor_; Logger* logger_; SharedHandle lastRequestHeader_; uint64_t lastContentLength_; std::stringstream lastBody_; bool keepAlive_; bool gzip_; std::string username_; std::string password_; bool acceptsPersistentConnection_; bool acceptsGZip_; public: HttpServer(const SharedHandle& socket, DownloadEngine* e); ~HttpServer(); SharedHandle receiveRequest(); bool receiveBody(); std::string getBody() const; const std::string& getRequestPath() const; void feedResponse(const std::string& text, const std::string& contentType); void feedResponse(const std::string& status, const std::string& headers, const std::string& text, const std::string& contentType); bool authenticate(); void setUsernamePassword (const std::string& username, const std::string& password) { username_ = username; password_ = 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_; } }; } // namespace aria2 #endif // _D_HTTP_SERVER_H_