8 #ifndef FACEBOOK_NETWORK_HTTP_CLIENT_H
9 #define FACEBOOK_NETWORK_HTTP_CLIENT_H
65 RC_MOVED_PERMANENTLY = 301,
69 RC_UNAUTHORIZED = 401,
71 RC_PAYMENT_REQUIRED = 402,
77 RC_METHOD_NOT_ALLOWED = 405,
79 RC_NOT_ACCEPTABLE = 406
96 typedef std::vector<std::string>
Lines;
115 inline size_t length()
const;
121 inline size_t contentLength()
const;
127 inline bool transferEncodingChunked()
const;
139 inline std::string& location();
145 inline const Lines& lines()
const;
151 inline void setCode(
const ReplyCode code);
157 inline void setVersion(
const std::string& version);
163 inline void setLength(
const size_t length);
169 inline void setContentLength(
const size_t length);
175 inline void setTransferEncodingChunked(
const bool state);
181 inline void setContentEncodingType(
const EncodingType type);
187 inline void setLocation(
const std::string& location);
193 inline void setLines(
Lines&& lines);
199 inline bool isValid()
const;
220 size_t contentLength_ = 0;
226 bool transferEncodingChunked_ =
false;
317 bool sendRequest(
const std::string& uri,
const std::string& requestMethod);
334 static bool url2uri(
const std::string& url, std::string& protocol, std::string& host, std::string& uri);
355 static bool appendData(
const HTTPHeader& header,
Buffer& buffer,
size_t& bufferPosition,
const char* payload,
size_t payloadSize,
size_t& pendingChunkSize);
364 static std::string
line(
const char* data,
const size_t size,
size_t& offset);
372 static bool hexToNumber(
const std::string& hex,
unsigned int& value);
414 return contentLength_;
419 return transferEncodingChunked_;
424 return encodingType_;
454 contentLength_ = length;
459 transferEncodingChunked_ = state;
464 encodingType_ = type;
469 location_ = location;
474 lines_ = std::move(lines);
479 return code_ != RC_INVALID;
This class implements a container for callback functions.
Definition: Callback.h:3456
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a thread-safe buffer queue.
Definition: BufferQueue.h:29
@ TYPE_READABLE
Readable endian type which is platform specific.
Definition: Data.h:37
This class implements a basic http client.
Definition: HTTPClient.h:26
bool invokeHeadRequest(const std::string &uri, HTTPHeader &header, const double timeout=5.0)
Invokes a HEAD request.
bool invokeGetRequest(const std::string &uri, Buffer &data, const double timeout=5.0, std::string *urlRedirection=nullptr, HTTPHeader::ReplyCode *replyCode=nullptr, bool *abort=nullptr, const ProgressCallback &progressCallback=ProgressCallback())
Invokes a GET request.
BufferQueue responseQueue_
The response data queue.
Definition: HTTPClient.h:396
ProtocolVersion version_
The version of the client.
Definition: HTTPClient.h:387
static bool hexToNumber(const std::string &hex, unsigned int &value)
Convert a hex string to a number.
static std::string line(const char *data, const size_t size, size_t &offset)
Returns one line from a data buffer.
static bool appendData(const HTTPHeader &header, Buffer &buffer, size_t &bufferPosition, const char *payload, size_t payloadSize, size_t &pendingChunkSize)
Appends response data from a current request to a given buffer.
bool sendRequest(const std::string &uri, const std::string &requestMethod)
Callback< void, size_t, size_t > ProgressCallback
Callback for receiving progress information when performing a HTTP request.
Definition: HTTPClient.h:248
HTTPClient(const std::string &host, const Port &port=Port(80, Port::TYPE_READABLE))
Creates a new HTTP client object.
bool connect(const std::string &host, const Port &port=Port(80, Port::TYPE_READABLE))
(Re-)connects the client with the HTTP server.
static bool url2uri(const std::string &url, std::string &protocol, std::string &host, std::string &uri)
Converts a URL to a URI.
bool connect()
Connects the client with the HTTP server.
static bool parseHeader(const char *data, const size_t size, HTTPHeader &header)
Parses a header from a given header string.
static std::string httpVersionString(const ProtocolVersion version)
Returns the HTTP version string for a given version number.
~HTTPClient()
Destructs a HTTP client object.
TCPClient tcpClient_
The TCP client of this HTTP client.
Definition: HTTPClient.h:384
void onResponse(const void *data, const size_t size)
The response event function.
std::vector< uint8_t > Buffer
Definition of a vector holding characters.
Definition: HTTPClient.h:241
static bool httpGetRequest(const std::string &url, Buffer &data, const Port &port=Port(80, Port::TYPE_READABLE), const double timeout=5.0, bool allowRedirect=true, std::string *redirectedURL=nullptr, HTTPHeader::ReplyCode *replyCode=nullptr, bool *abort=nullptr, const ProgressCallback &progressCallback=ProgressCallback())
Helper function to executes an HTTP site/file request.
std::string host_
The URL of the HTTP server.
Definition: HTTPClient.h:390
Lock lock_
The lock of the client.
Definition: HTTPClient.h:399
Port port_
The port of the HTTP server.
Definition: HTTPClient.h:393
ProtocolVersion
Definition of individual protocol versions.
Definition: HTTPClient.h:33
@ PV_HTTP_1_0
The HTTP 1.0 version.
Definition: HTTPClient.h:35
This class wraps a port number with 16 bits.
Definition: Port.h:26
This class implements a TCP client.
Definition: TCPClient.h:27
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15