/* */ #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_