/* */ #ifndef _D_HTTP_REQUEST_H_ #define _D_HTTP_REQUEST_H_ #include "common.h" #include "SharedHandle.h" #include #include namespace aria2 { class Request; class Segment; class Range; class Option; class HttpRequest { private: static std::string USER_AGENT; SharedHandle request; SharedHandle segment; uint64_t entityLength; bool authEnabled; bool proxyEnabled; bool proxyAuthEnabled; std::string userAgent; std::deque _headers; std::string getHostText(const std::string& host, uint16_t port) const; std::string getProxyAuthString() const; public: HttpRequest(); SharedHandle getSegment() const; void setSegment(const SharedHandle& segment); void setRequest(const SharedHandle& request); /** * entityLength is used in isRangeSatisfied() method. */ void setEntityLength(uint64_t entityLength) { this->entityLength = entityLength; } uint64_t getEntityLength() const { return entityLength; } std::string getHost() const; uint16_t getPort() const; std::string getMethod() const; std::string getProtocol() const; std::string getCurrentURI() const; std::string getDir() const; std::string getFile() const; std::string getPreviousURI() const; SharedHandle getRange() const; /** * Inspects whether the specified response range is satisfiable * with request range. */ bool isRangeSatisfied(const SharedHandle& range) const; SharedHandle getRequest() const; off_t getStartByte() const; off_t getEndByte() const; /** * Returns string representation of http request. * It usually starts with "GET ..." and ends with "\r\n". */ std::string createRequest() const; /** * Returns string representation of http tunnel request. * It usually starts with "CONNECT ..." and ends with "\r\n". */ std::string createProxyRequest() const; /** * Configures this object with option. * Following values are evaluated: * PREF_HTTP_AUTH_ENABLED, PREF_HTTP_PROXY_ENABLED, * PREF_HTTP_PROXY_METHOD, PREF_HTTP_PROXY_AUTH_ENABLED, * PREF_HTTP_USER, PREF_HTTP_PASSWD, * PREF_HTTP_PROXY_USER, PREF_HTTP_PROXY_PASSWD * The evaluation results are stored in instance variables. */ void configure(const Option* option); void setProxyEnabled(bool proxyEnabled) { this->proxyEnabled = proxyEnabled; } void setProxyAuthEnabled(bool proxyAuthEnabled) { this->proxyAuthEnabled = proxyAuthEnabled; } void setAuthEnabled(bool authEnabled) { this->authEnabled = authEnabled; } void setUserAgent(const std::string& userAgent) { this->userAgent = userAgent; } // accepts multiline headers, deliminated by LF void addHeader(const std::string& headers); }; typedef SharedHandle HttpRequestHandle; typedef std::deque HttpRequests; } // namespace aria2 #endif // _D_HTTP_REQUEST_H_