2012-06-03 17:01:08 +00:00
|
|
|
#ifndef _NET_HTTP_HTTP_CLIENT
|
|
|
|
#define _NET_HTTP_HTTP_CLIENT
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "base/buffer.h"
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#else
|
|
|
|
#include <winsock2.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
class Connection {
|
2012-10-30 12:20:55 +00:00
|
|
|
public:
|
|
|
|
Connection();
|
|
|
|
virtual ~Connection();
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
// Inits the sockaddr_in.
|
|
|
|
bool Resolve(const char *host, int port);
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
void Connect();
|
|
|
|
void Disconnect();
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
// Disconnects, and connects. Doesn't re-resolve.
|
|
|
|
void Reconnect();
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
// Only to be used for bring-up and debugging.
|
|
|
|
uintptr_t sock() const { return sock_; }
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
protected:
|
|
|
|
// Store the remote host here, so we can send it along through HTTP/1.1 requests.
|
|
|
|
// TODO: Move to http::client?
|
|
|
|
std::string host_;
|
|
|
|
int port_;
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
sockaddr_in remote_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uintptr_t sock_;
|
2012-06-03 17:01:08 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
} // namespace net
|
2012-06-03 17:01:08 +00:00
|
|
|
|
|
|
|
namespace http {
|
|
|
|
|
|
|
|
class Client : public net::Connection {
|
2012-10-30 12:20:55 +00:00
|
|
|
public:
|
|
|
|
Client();
|
|
|
|
~Client();
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
void GET(const char *resource, Buffer *output);
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
// Return value is the HTTP return code.
|
|
|
|
int POST(const char *resource, const std::string &data, Buffer *output);
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
// HEAD, PUT, DELETE aren't implemented yet.
|
2012-06-03 17:01:08 +00:00
|
|
|
};
|
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
} // http
|
2012-06-03 17:01:08 +00:00
|
|
|
|
2012-10-30 12:20:55 +00:00
|
|
|
#endif // _NET_HTTP_HTTP_CLIENT
|
2012-06-03 17:01:08 +00:00
|
|
|
|