X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2FHTTPRequest.hxx;h=0c6e2685c6f1df956d95d1bf2388600b27c5ea8c;hb=201cb61f842ef50a19438e3872ba22e588fa1afc;hp=8c0fcbac13895de02456e848e9ad435e98065c07;hpb=a2249becba1d574d567791ef8b03ef50b129eb90;p=simgear.git diff --git a/simgear/io/HTTPRequest.hxx b/simgear/io/HTTPRequest.hxx index 8c0fcbac..0c6e2685 100644 --- a/simgear/io/HTTPRequest.hxx +++ b/simgear/io/HTTPRequest.hxx @@ -30,6 +30,7 @@ public: virtual std::string host() const; virtual std::string hostAndPort() const; virtual unsigned short port() const; + virtual std::string query() const; virtual string_list requestHeaders() const; virtual std::string header(const std::string& name) const; @@ -40,24 +41,72 @@ public: virtual std::string responseReason() const { return _responseReason; } - virtual unsigned int contentLength() const; -protected: - friend class Connection; + void setResponseLength(unsigned int l); + virtual unsigned int responseLength() const; + + /** + * Query the size of the request body. -1 (the default value) means no + * request body + */ + virtual int requestBodyLength() const; + + /** + * Retrieve the body data bytes. Will be passed the maximum body bytes + * to return in the buffer, and should update count with the actual number + * of bytes written. + */ + virtual void getBodyData(char* s, int& count) const; + + /** + * retrieve the request body content type. Default is text/plain + */ + virtual std::string requestBodyType() const; + + /** + * running total of body bytes received so far. Can be used + * to generate a completion percentage, if the response length is + * known. + */ + unsigned int responseBytesReceived() const + { return _receivedBodyBytes; } + + enum HTTPVersion { + HTTP_VERSION_UNKNOWN = 0, + HTTP_0_x, // 0.9 or similar + HTTP_1_0, + HTTP_1_1 + }; + + HTTPVersion responseVersion() const + { return _responseVersion; } + static HTTPVersion decodeVersion(const std::string& v); + + bool closeAfterComplete() const; +protected: Request(const std::string& url, const std::string method = "GET"); virtual void responseStart(const std::string& r); virtual void responseHeader(const std::string& key, const std::string& value); virtual void responseHeadersComplete(); virtual void responseComplete(); - + virtual void failed(); virtual void gotBodyData(const char* s, int n); private: + friend class Client; + friend class Connection; + + void processBodyBytes(const char* s, int n); + void setFailure(int code, const std::string& reason); std::string _method; std::string _url; + HTTPVersion _responseVersion; int _responseStatus; std::string _responseReason; + unsigned int _responseLength; + unsigned int _receivedBodyBytes; + bool _willClose; typedef std::map HeaderDict; HeaderDict _responseHeaders;