C++ Rest SDK
The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
|
Represents an HTTP response. More...
#include <http_msg.h>
Public Member Functions | |
http_response () | |
Constructs a response with an empty status code, no headers, and no body. More... | |
http_response (http::status_code code) | |
Constructs a response with given status code, no headers, and no body. More... | |
http::status_code | status_code () const |
Gets the status code of the response message. More... | |
void | set_status_code (http::status_code code) const |
Sets the status code of the response message. More... | |
const http::reason_phrase & | reason_phrase () const |
Gets the reason phrase of the response message. If no reason phrase is set it will default to the standard one corresponding to the status code. More... | |
void | set_reason_phrase (const http::reason_phrase &reason) const |
Sets the reason phrase of the response message. If no reason phrase is set it will default to the standard one corresponding to the status code. More... | |
http_headers & | headers () |
Gets the headers of the response message. More... | |
const http_headers & | headers () const |
Gets a const reference to the headers of the response message. More... | |
utility::string_t | to_string () const |
Generates a string representation of the message, including the body when possible. Mainly this should be used for debugging purposes as it has to copy the message body and doesn't have excellent performance. More... | |
pplx::task< utility::string_t > | extract_string (bool ignore_content_type=false) const |
Extracts the body of the response message as a string value, checking that the content type is a MIME text type. A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out. More... | |
pplx::task< utf8string > | extract_utf8string (bool ignore_content_type=false) const |
Extracts the body of the response message as a UTF-8 string value, checking that the content type is a MIME text type. A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out. More... | |
pplx::task< utf16string > | extract_utf16string (bool ignore_content_type=false) const |
Extracts the body of the response message as a UTF-16 string value, checking that the content type is a MIME text type. A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out. More... | |
pplx::task< json::value > | extract_json (bool ignore_content_type=false) const |
Extracts the body of the response message into a json value, checking that the content type is application/json. A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out. More... | |
pplx::task< std::vector< unsigned char > > | extract_vector () const |
Extracts the body of the response message into a vector of bytes. More... | |
void | set_body (utf8string &&body_text, const utf8string &content_type=utf8string("text/plain; charset=utf-8")) |
Sets the body of the message to a textual string and set the "Content-Type" header. Assumes the character encoding of the string is UTF-8. More... | |
void | set_body (const utf8string &body_text, const utf8string &content_type=utf8string("text/plain; charset=utf-8")) |
Sets the body of the message to a textual string and set the "Content-Type" header. Assumes the character encoding of the string is UTF-8. More... | |
void | set_body (const utf16string &body_text, utf16string content_type=::utility::conversions::to_utf16string("text/plain")) |
Sets the body of the message to a textual string and set the "Content-Type" header. Assumes the character encoding of the string is UTF-16 will perform conversion to UTF-8. More... | |
void | set_body (const json::value &body_data) |
Sets the body of the message to contain json value. If the 'Content-Type' header hasn't already been set it will be set to 'application/json'. More... | |
void | set_body (std::vector< unsigned char > &&body_data) |
Sets the body of the message to the contents of a byte vector. If the 'Content-Type' header hasn't already been set it will be set to 'application/octet-stream'. More... | |
void | set_body (const std::vector< unsigned char > &body_data) |
Sets the body of the message to the contents of a byte vector. If the 'Content-Type' header hasn't already been set it will be set to 'application/octet-stream'. More... | |
void | set_body (const concurrency::streams::istream &stream, const utility::string_t &content_type=_XPLATSTR("application/octet-stream")) |
Defines a stream that will be relied on to provide the body of the HTTP message when it is sent. More... | |
void | set_body (const concurrency::streams::istream &stream, utility::size64_t content_length, const utility::string_t &content_type=_XPLATSTR("application/octet-stream")) |
Defines a stream that will be relied on to provide the body of the HTTP message when it is sent. More... | |
concurrency::streams::istream | body () const |
Produces a stream which the caller may use to retrieve data from an incoming request. More... | |
pplx::task< http::http_response > | content_ready () const |
Signals the user (client) when all the data for this response message has been received. More... | |
std::shared_ptr< http::details::_http_response > | _get_impl () const |
http::details::_http_server_context * | _get_server_context () const |
void | _set_server_context (std::unique_ptr< http::details::_http_server_context > server_context) |
Represents an HTTP response.
|
inline |
Constructs a response with an empty status code, no headers, and no body.
|
inline |
Constructs a response with given status code, no headers, and no body.
code | HTTP status code to use in response. |
|
inline |
Produces a stream which the caller may use to retrieve data from an incoming request.
This cannot be used in conjunction with any other means of getting the body of the request. It is not necessary to wait until the message has been sent before starting to write to the stream, but it is advisable to do so, since it will allow the network I/O to start earlier and the work of sending data can be overlapped with the production of more data.
|
inline |
Signals the user (client) when all the data for this response message has been received.
task
which is completed when all of the response body has been received.
|
inline |
Extracts the body of the response message into a json value, checking that the content type is application/json. A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out.
ignore_content_type | If true, ignores the Content-Type header and assumes UTF-8. |
|
inline |
Extracts the body of the response message as a string value, checking that the content type is a MIME text type. A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out.
ignore_content_type | If true, ignores the Content-Type header and assumes UTF-8. |
|
inline |
Extracts the body of the response message as a UTF-16 string value, checking that the content type is a MIME text type. A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out.
ignore_content_type | If true, ignores the Content-Type header and assumes UTF-16. |
|
inline |
Extracts the body of the response message as a UTF-8 string value, checking that the content type is a MIME text type. A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out.
ignore_content_type | If true, ignores the Content-Type header and assumes UTF-8. |
|
inline |
Extracts the body of the response message into a vector of bytes.
|
inline |
Gets the headers of the response message.
Use the
to fill in desired headers.
|
inline |
Gets a const reference to the headers of the response message.
|
inline |
Gets the reason phrase of the response message. If no reason phrase is set it will default to the standard one corresponding to the status code.
|
inline |
Sets the body of the message to a textual string and set the "Content-Type" header. Assumes the character encoding of the string is UTF-8.
body_text | String containing body text. |
content_type | MIME type to set the "Content-Type" header to. Default to "text/plain; charset=utf-8". |
This will overwrite any previously set body data and "Content-Type" header.
|
inline |
Sets the body of the message to a textual string and set the "Content-Type" header. Assumes the character encoding of the string is UTF-8.
body_text | String containing body text. |
content_type | MIME type to set the "Content-Type" header to. Default to "text/plain; charset=utf-8". |
This will overwrite any previously set body data and "Content-Type" header.
|
inline |
Sets the body of the message to a textual string and set the "Content-Type" header. Assumes the character encoding of the string is UTF-16 will perform conversion to UTF-8.
body_text | String containing body text. |
content_type | MIME type to set the "Content-Type" header to. Default to "text/plain". |
This will overwrite any previously set body data and "Content-Type" header.
|
inline |
Sets the body of the message to contain json value. If the 'Content-Type' header hasn't already been set it will be set to 'application/json'.
body_text | json value. |
This will overwrite any previously set body data.
|
inline |
Sets the body of the message to the contents of a byte vector. If the 'Content-Type' header hasn't already been set it will be set to 'application/octet-stream'.
body_data | Vector containing body data. |
This will overwrite any previously set body data.
|
inline |
Sets the body of the message to the contents of a byte vector. If the 'Content-Type' header hasn't already been set it will be set to 'application/octet-stream'.
body_data | Vector containing body data. |
This will overwrite any previously set body data.
|
inline |
Defines a stream that will be relied on to provide the body of the HTTP message when it is sent.
stream | A readable, open asynchronous stream. |
content_type | A string holding the MIME type of the message body. |
This cannot be used in conjunction with any other means of setting the body of the request. The stream will not be read until the message is sent.
|
inline |
Defines a stream that will be relied on to provide the body of the HTTP message when it is sent.
stream | A readable, open asynchronous stream. |
content_length | The size of the data to be sent in the body. |
content_type | A string holding the MIME type of the message body. |
This cannot be used in conjunction with any other means of setting the body of the request. The stream will not be read until the message is sent.
|
inline |
Sets the reason phrase of the response message. If no reason phrase is set it will default to the standard one corresponding to the status code.
reason | The reason phrase to set. |
|
inline |
Sets the status code of the response message.
code | Status code to set. |
This will overwrite any previously set status code.
|
inline |
Gets the status code of the response message.
|
inline |
Generates a string representation of the message, including the body when possible. Mainly this should be used for debugging purposes as it has to copy the message body and doesn't have excellent performance.
Note this function is synchronous and doesn't wait for the entire message body to arrive. If the message body has arrived by the time this function is called and it is has a textual Content-Type it will be included. Otherwise just the headers will be present.