C++ edjLibrary SDK
|
An HTTP fetch request includes body, headers, version, method, and URI. More...
#include <fetch.hpp>
Public Member Functions | |
HttpFetch (http::Uri uri, http::HttpMethod method) | |
Creates a request with the given method and URI, version as HTTP/1.1, no headers, and no body. More... | |
HttpFetch & | set_version (http::HttpVersion version) |
Sets the HTTP version of the request. More... | |
http::HttpVersion | get_version () const |
Gets the HTTP version of the request. More... | |
HttpFetch & | set_header (const std::string &header_name, const std::string &value) |
Sets a request header to the given value. More... | |
HttpFetch & | set_header (const std::string &header_name, const std::vector< std::string > &value) |
Sets a request header to the given values. More... | |
HttpFetch & | append_header (const std::string &header_name, const std::string &value) |
Appends a value to the existing request header. More... | |
HttpFetch & | set_headers (const edjx::http::HttpHeaders &value) |
Set request headers to the given values. More... | |
const edjx::http::HttpHeaders & | get_headers () const |
Returns a const reference to the request header map. More... | |
HttpFetch & | set_body (const std::string &text) |
Sets the given [text ] value as the body of the request. More... | |
HttpFetch & | set_body (const std::vector< std::uint8_t > bytes) |
Sets the given [bytes ] value as the body of the request. More... | |
const std::vector< uint8_t > & | get_body () const |
Returns a constant reference to the body. More... | |
edjx::error::HttpError | send (FetchResponse &response) |
Sends the request to the server, and returns after the response is received or an error occurs. More... | |
edjx::error::HttpError | send_streaming (FetchResponsePending &response, edjx::stream::WriteStream &write_stream) |
Starts streaming an HTTP Fetch request to the server. This method returns a FetchResponsePending object and an edjx::stream::WriteStream object. The edjx::stream::WriteStream object is used to stream data. The FetchResponsePending is a placeholder to retreive FetchResponse . In the background, this method triggers sending HTTP headers and other HTTP artifacts to the server. More... | |
Public Attributes | |
http::HttpVersion | version |
HTTP version of the request. More... | |
edjx::http::HttpHeaders | headers |
Headers for the request. More... | |
http::Uri | uri |
URI of the request. More... | |
http::HttpMethod | method |
Method for the request. More... | |
std::vector< uint8_t > | body |
Request body. More... | |
An HTTP fetch request includes body, headers, version, method, and URI.
|
inline |
Creates a request with the given method and URI, version as HTTP/1.1, no headers, and no body.
uri | Request URI |
method | Request method |
HttpFetch & edjx::fetch::HttpFetch::append_header | ( | const std::string & | header_name, |
const std::string & | value | ||
) |
Appends a value to the existing request header.
Keeps any previous values for the given header name.
header_name | Header name |
value | Header value |
const std::vector< uint8_t > & edjx::fetch::HttpFetch::get_body | ( | ) | const |
Returns a constant reference to the body.
const edjx::http::HttpHeaders & edjx::fetch::HttpFetch::get_headers | ( | ) | const |
Returns a const reference to the request header map.
http::HttpVersion edjx::fetch::HttpFetch::get_version | ( | ) | const |
Gets the HTTP version of the request.
edjx::error::HttpError edjx::fetch::HttpFetch::send | ( | FetchResponse & | response | ) |
Sends the request to the server, and returns after the response is received or an error occurs.
response |
edjx::error::HttpError edjx::fetch::HttpFetch::send_streaming | ( | FetchResponsePending & | response, |
edjx::stream::WriteStream & | write_stream | ||
) |
Starts streaming an HTTP Fetch request to the server. This method returns a FetchResponsePending
object and an edjx::stream::WriteStream
object. The edjx::stream::WriteStream
object is used to stream data. The FetchResponsePending
is a placeholder to retreive FetchResponse
. In the background, this method triggers sending HTTP headers and other HTTP artifacts to the server.
This method and the send() method cannot be used together.
response | A placeholder for the server's response will be copied to this object. It can retreive the server's response once the response is received. |
write_stream | A write stream for streaming the HTTP Fetch request body. |
HttpFetch & edjx::fetch::HttpFetch::set_body | ( | const std::string & | text | ) |
Sets the given [text
] value as the body of the request.
Any body that was previously set on the request is discarded.
text | String to be used as the body |
HttpFetch & edjx::fetch::HttpFetch::set_body | ( | const std::vector< std::uint8_t > | bytes | ) |
Sets the given [bytes
] value as the body of the request.
Any body that was previously set on the request is discarded.
bytes | Bytes to be used as the body |
HttpFetch & edjx::fetch::HttpFetch::set_header | ( | const std::string & | header_name, |
const std::string & | value | ||
) |
Sets a request header to the given value.
Discards any previous values for the given header name.
header_name | Header name |
value | Header value |
HttpFetch & edjx::fetch::HttpFetch::set_header | ( | const std::string & | header_name, |
const std::vector< std::string > & | value | ||
) |
Sets a request header to the given values.
Discards any previous values for the given header name.
header_name | Header name |
value | Header values |
HttpFetch & edjx::fetch::HttpFetch::set_headers | ( | const edjx::http::HttpHeaders & | value | ) |
Set request headers to the given values.
All previously defined headers will be discarded.
value | HTTP headers |
HttpFetch & edjx::fetch::HttpFetch::set_version | ( | http::HttpVersion | version | ) |
Sets the HTTP version of the request.
version | Version to be set |
std::vector<uint8_t> edjx::fetch::HttpFetch::body |
Request body.
edjx::http::HttpHeaders edjx::fetch::HttpFetch::headers |
Headers for the request.
http::HttpMethod edjx::fetch::HttpFetch::method |
Method for the request.
http::Uri edjx::fetch::HttpFetch::uri |
URI of the request.
http::HttpVersion edjx::fetch::HttpFetch::version |
HTTP version of the request.