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 * Query the size of the request body. -1 (the default value) means no
51 virtual int requestBodyLength() const;
54 * Retrieve the body data bytes. Will be passed the maximum body bytes
55 * to return in the buffer, and should update count with the actual number
58 virtual void getBodyData(char* s, int& count) const;
61 * retrieve the request body content type. Default is text/plain
63 virtual std::string requestBodyType() const;
66 * running total of body bytes received so far. Can be used
67 * to generate a completion percentage, if the response length is
70 unsigned int responseBytesReceived() const
71 { return _receivedBodyBytes; }
74 HTTP_VERSION_UNKNOWN = 0,
75 HTTP_0_x, // 0.9 or similar
80 HTTPVersion responseVersion() const
81 { return _responseVersion; }
83 static HTTPVersion decodeVersion(const std::string& v);
85 bool closeAfterComplete() const;
87 Request(const std::string& url, const std::string method = "GET");
89 virtual void responseStart(const std::string& r);
90 virtual void responseHeader(const std::string& key, const std::string& value);
91 virtual void responseHeadersComplete();
92 virtual void responseComplete();
93 virtual void failed();
94 virtual void gotBodyData(const char* s, int n);
97 friend class Connection;
99 void processBodyBytes(const char* s, int n);
100 void setFailure(int code, const std::string& reason);
104 HTTPVersion _responseVersion;
106 std::string _responseReason;
107 unsigned int _responseLength;
108 unsigned int _receivedBodyBytes;
111 typedef std::map<std::string, std::string> HeaderDict;
112 HeaderDict _responseHeaders;
115 typedef SGSharedPtr<Request> Request_ptr;
117 } // of namespace HTTP
119 } // of namespace simgear
121 #endif // of SG_HTTP_REQUEST_HXX