]> git.mxchange.org Git - simgear.git/blob - simgear/io/HTTPRequest.hxx
Tiny HTTP client layer on top of NetChat - and CTest support for some SimGear tests.
[simgear.git] / simgear / io / HTTPRequest.hxx
1 #ifndef SG_HTTP_REQUEST_HXX
2 #define SG_HTTP_REQUEST_HXX
3
4 #include <map>
5
6 #include <simgear/structure/SGReferenced.hxx>
7 #include <simgear/structure/SGSharedPtr.hxx>
8 #include <simgear/math/sg_types.hxx>
9
10 namespace simgear
11 {
12
13 namespace HTTP
14 {
15
16 class Request : public SGReferenced
17 {
18 public:
19     virtual ~Request();
20     
21     virtual std::string method() const
22         { return _method; }
23     virtual std::string url() const
24         { return _url; }
25     
26     virtual std::string scheme() const;
27     virtual std::string path() const;
28     virtual std::string host() const; // host, including port
29     
30     virtual string_list requestHeaders() const;
31     virtual std::string header(const std::string& name) const;
32
33     virtual int responseCode() const
34         { return _responseStatus; }
35         
36     virtual std::string resposeReason() const
37         { return _responseReason; }
38         
39     virtual int contentLength() const;
40 protected:
41     friend class Connection;
42     
43     Request(const std::string& url, const std::string method = "get");
44
45     virtual void responseStart(const std::string& r);
46     virtual void responseHeader(const std::string& key, const std::string& value);
47     virtual void responseHeadersComplete();
48     virtual void responseComplete();
49     
50     virtual void gotBodyData(const char* s, int n);
51 private:
52
53     std::string _method;
54     std::string _url;
55     int _responseStatus;
56     std::string _responseReason;
57     
58     typedef std::map<std::string, std::string> HeaderDict;
59     HeaderDict _responseHeaders; 
60 };
61
62 typedef SGSharedPtr<Request> Request_ptr;
63
64 } // of namespace HTTP
65
66 } // of namespace simgear
67
68 #endif // of SG_HTTP_REQUEST_HXX
69