1 #ifndef SG_HTTP_REQUEST_HXX
2 #define SG_HTTP_REQUEST_HXX
6 #include <simgear/structure/SGReferenced.hxx>
7 #include <simgear/structure/SGSharedPtr.hxx>
8 #include <simgear/math/sg_types.hxx>
16 class Request : public SGReferenced
21 virtual void setUrl(const std::string& url);
23 virtual std::string method() const
25 virtual std::string url() const
28 virtual std::string scheme() const;
29 virtual std::string path() const;
30 virtual std::string host() const;
31 virtual std::string hostAndPort() const;
32 virtual unsigned short port() const;
34 virtual string_list requestHeaders() const;
35 virtual std::string header(const std::string& name) const;
37 virtual int responseCode() const
38 { return _responseStatus; }
40 virtual std::string responseReason() const
41 { return _responseReason; }
43 void setResponseLength(unsigned int l);
44 virtual unsigned int responseLength() const;
47 * running total of body bytes received so far. Can be used
48 * to generate a completion percentage, if the response length is
51 unsigned int responseBytesReceived() const
52 { return _receivedBodyBytes; }
54 Request(const std::string& url, const std::string method = "GET");
56 virtual void responseStart(const std::string& r);
57 virtual void responseHeader(const std::string& key, const std::string& value);
58 virtual void responseHeadersComplete();
59 virtual void responseComplete();
60 virtual void failed();
61 virtual void gotBodyData(const char* s, int n);
64 friend class Connection;
66 void processBodyBytes(const char* s, int n);
67 void setFailure(int code, const std::string& reason);
72 std::string _responseReason;
73 unsigned int _responseLength;
74 unsigned int _receivedBodyBytes;
76 typedef std::map<std::string, std::string> HeaderDict;
77 HeaderDict _responseHeaders;
80 typedef SGSharedPtr<Request> Request_ptr;
82 } // of namespace HTTP
84 } // of namespace simgear
86 #endif // of SG_HTTP_REQUEST_HXX