Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
httpclient.h
Go to the documentation of this file.
1 
18 #ifndef ION_REMOTE_HTTPCLIENT_H_
19 #define ION_REMOTE_HTTPCLIENT_H_
20 
21 #include <map>
22 #include <string>
23 
24 #include "base/integral_types.h"
25 
26 namespace ion {
27 namespace remote {
28 
32 class HttpClient {
33  public:
35  struct Url {
37  Url();
39  explicit Url(const std::string& url);
41  void Set(const std::string& url);
42 
45  bool IsValid() const;
46 
48  int port;
50  bool is_https;
52  std::string hostname;
54  std::string path;
57  std::map<std::string, std::string> args;
58  };
59 
60  struct Response {
61  Response();
65  int status;
67  std::string data;
71  std::map<std::string, std::string> headers;
72  };
73 
74  HttpClient();
75  virtual ~HttpClient();
76 
78  virtual const Response Get(const std::string& url) const;
81  virtual const Response GetRange(const std::string& url, int64 start,
82  int64 end) const;
84  virtual const Response Head(const std::string& url) const;
86  virtual const Response Post(const std::string& url, const std::string& data);
88  virtual const Response Put(const std::string& url, const std::string& data);
89 };
90 
91 } // namespace remote
92 } // namespace ion
93 
94 #endif // ION_REMOTE_HTTPCLIENT_H_
virtual const Response Head(const std::string &url) const
Sends a HEAD request for a URL and returns the remote host's response.
Definition: httpclient.cc:230
Url url
The requested Url that produced the response.
Definition: httpclient.h:63
std::map< std::string, std::string > headers
Headers returned by the remote host.
Definition: httpclient.h:71
Simple wrapper around a URL.
Definition: httpclient.h:35
virtual const Response GetRange(const std::string &url, int64 start, int64 end) const
Sends a GET request for the passed byte range and returns the remote host's response.
Definition: httpclient.cc:225
virtual const Response Put(const std::string &url, const std::string &data)
PUTs data to URL and returns the remote host's response.
Definition: httpclient.cc:239
virtual const Response Get(const std::string &url) const
Sends a GET request for a URL and returns the remote host's response.
Definition: httpclient.cc:221
Url()
Constructs an empty, invalid Url.
Definition: httpclient.cc:114
bool is_https
Whether the connection is HTTPS or HTTP.
Definition: httpclient.h:50
std::string data
Data received from the last interaction with the remote host.
Definition: httpclient.h:67
std::string hostname
The remote host's name.
Definition: httpclient.h:52
bool IsValid() const
Returns whether this Url is valid.
Definition: httpclient.cc:208
int port
The remote host's port.
Definition: httpclient.h:48
std::string path
The path on the remote host.
Definition: httpclient.h:54
void Set(const std::string &url)
Sets the url from the passed value.
Definition: httpclient.cc:121
int status
The status code received from the remote host (e.g., 200, 404);.
Definition: httpclient.h:65
HttpClient is a very basic class that sends HTTP requests and returns the server's response...
Definition: httpclient.h:32
virtual const Response Post(const std::string &url, const std::string &data)
POSTs data to URL and returns the remote host's response.
Definition: httpclient.cc:234
std::map< std::string, std::string > args
Any query arguments in the Url.
Definition: httpclient.h:57