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;
33 virtual std::string query() const;
35 virtual string_list requestHeaders() const;
36 virtual std::string header(const std::string& name) const;
38 virtual int responseCode() const
39 { return _responseStatus; }
41 virtual std::string responseReason() const
42 { return _responseReason; }
44 void setResponseLength(unsigned int l);
45 virtual unsigned int responseLength() const;
48 * running total of body bytes received so far. Can be used
49 * to generate a completion percentage, if the response length is
52 unsigned int responseBytesReceived() const
53 { return _receivedBodyBytes; }
56 HTTP_VERSION_UNKNOWN = 0,
57 HTTP_0_x, // 0.9 or similar
62 HTTPVersion responseVersion() const
63 { return _responseVersion; }
65 static HTTPVersion decodeVersion(const std::string& v);
67 bool closeAfterComplete() const;
69 Request(const std::string& url, const std::string method = "GET");
71 virtual void responseStart(const std::string& r);
72 virtual void responseHeader(const std::string& key, const std::string& value);
73 virtual void responseHeadersComplete();
74 virtual void responseComplete();
75 virtual void failed();
76 virtual void gotBodyData(const char* s, int n);
79 friend class Connection;
81 void processBodyBytes(const char* s, int n);
82 void setFailure(int code, const std::string& reason);
86 HTTPVersion _responseVersion;
88 std::string _responseReason;
89 unsigned int _responseLength;
90 unsigned int _receivedBodyBytes;
93 typedef std::map<std::string, std::string> HeaderDict;
94 HeaderDict _responseHeaders;
97 typedef SGSharedPtr<Request> Request_ptr;
99 } // of namespace HTTP
101 } // of namespace simgear
103 #endif // of SG_HTTP_REQUEST_HXX