31 #include <system_error>
33 #include "pplx/pplxtasks.h"
34 #include "cpprest/json.h"
35 #include "cpprest/uri.h"
36 #include "cpprest/http_headers.h"
37 #include "cpprest/details/cpprest_compat.h"
38 #include "cpprest/asyncrt_utils.h"
39 #include "cpprest/streams.h"
40 #include "cpprest/containerstream.h"
71 #define DAT(a,b) _ASYNCRTIMP const static method a;
72 #include "cpprest/details/http_constants.dat"
77 typedef unsigned short status_code;
86 #define DAT(a,b,c) const static status_code a=b;
87 #include "cpprest/details/http_constants.dat"
93 namespace message_direction
105 typedef utility::string_t reason_phrase;
106 typedef std::function<void(message_direction::direction, utility::size64_t)> progress_handler;
111 reason_phrase phrase;
120 #define _HEADER_NAMES
121 #define DAT(a,b) _ASYNCRTIMP const static utility::string_t a;
122 #include "cpprest/details/http_constants.dat"
139 : m_msg(
utility::conversions::to_utf8string(whatArg)) {}
142 http_exception(std::string whatArg) : m_msg(std::move(whatArg)) {}
155 : m_errorCode(
utility::details::create_error_code(errorCode))
157 m_msg = m_errorCode.message();
166 : m_errorCode(
utility::details::create_error_code(errorCode)),
167 m_msg(
utility::conversions::to_utf8string(whatArg))
177 m_errorCode(
utility::details::create_error_code(errorCode)),
178 m_msg(std::move(whatArg))
190 m_msg = m_errorCode.message();
197 const char*
what() const CPPREST_NOEXCEPT
199 return m_msg.c_str();
212 std::error_code m_errorCode;
232 virtual ~http_msg_base() {}
236 _ASYNCRTIMP
void set_body(
const concurrency::streams::istream &
instream,
const utf8string &contentType);
237 _ASYNCRTIMP
void set_body(
const concurrency::streams::istream &instream,
const utf16string &contentType);
238 _ASYNCRTIMP
void set_body(
const concurrency::streams::istream &instream, utility::size64_t contentLength,
const utf8string &contentType);
239 _ASYNCRTIMP
void set_body(
const concurrency::streams::istream &instream, utility::size64_t contentLength,
const utf16string &contentType);
248 utility::string_t
parse_and_check_content_type(
bool ignore_content_type,
const std::function<
bool(
const utility::string_t&)> &check_content_type);
250 _ASYNCRTIMP utf8string extract_utf8string(
bool ignore_content_type =
false);
251 _ASYNCRTIMP utf16string extract_utf16string(
bool ignore_content_type =
false);
252 _ASYNCRTIMP utility::string_t extract_string(
bool ignore_content_type =
false);
254 _ASYNCRTIMP
json::value _extract_json(
bool ignore_content_type =
false);
255 _ASYNCRTIMP std::vector<unsigned char> _extract_vector();
257 virtual _ASYNCRTIMP utility::string_t to_string()
const;
262 virtual _ASYNCRTIMP
void _complete(utility::size64_t bodySize,
const std::exception_ptr &exceptionPtr = std::exception_ptr());
328 bool m_default_outstream;
352 _http_response() : m_status_code((std::numeric_limits<uint16_t>::max)()) { }
356 http::status_code status_code()
const {
return m_status_code; }
358 void set_status_code(http::status_code code) { m_status_code = code; }
360 const http::reason_phrase & reason_phrase()
const {
return m_reason_phrase; }
362 void set_reason_phrase(
const http::reason_phrase &reason) { m_reason_phrase = reason; }
364 _ASYNCRTIMP utility::string_t to_string()
const;
368 void _set_server_context(std::unique_ptr<details::_http_server_context> server_context) { m_server_context = std::move(server_context); }
371 std::unique_ptr<_http_server_context> m_server_context;
373 http::status_code m_status_code;
374 http::reason_phrase m_reason_phrase;
399 : _m_impl(std::make_shared<details::_http_response>(code)) { }
405 http::status_code
status_code()
const {
return _m_impl->status_code(); }
414 void set_status_code(http::status_code code)
const { _m_impl->set_status_code(code); }
421 const http::reason_phrase &
reason_phrase()
const {
return _m_impl->reason_phrase(); }
428 void set_reason_phrase(
const http::reason_phrase &reason)
const { _m_impl->set_reason_phrase(reason); }
455 utility::string_t
to_string()
const {
return _m_impl->to_string(); }
466 return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) {
return impl->extract_string(ignore_content_type); });
478 return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) {
return impl->extract_utf8string(ignore_content_type); });
490 return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) {
return impl->extract_utf16string(ignore_content_type); });
502 return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) {
return impl->_extract_json(ignore_content_type); });
512 return pplx::create_task(_m_impl->_get_data_available()).then([impl](utility::size64_t) {
return impl->_extract_vector(); });
524 void set_body(utf8string &&body_text,
const utf8string &content_type = utf8string(
"text/plain; charset=utf-8"))
526 const auto length = body_text.size();
527 _m_impl->set_body(concurrency::streams::bytestream::open_istream<std::string>(std::move(body_text)), length, content_type);
539 void set_body(
const utf8string &body_text,
const utf8string &content_type = utf8string(
"text/plain; charset=utf-8"))
541 _m_impl->set_body(concurrency::streams::bytestream::open_istream<std::string>(body_text), body_text.size(), content_type);
557 throw std::invalid_argument(
"content_type can't contain a 'charset'.");
561 auto length = utf8body.size();
562 _m_impl->set_body(concurrency::streams::bytestream::open_istream<std::string>(
563 std::move(utf8body)),
579 auto length = body_text.size();
580 set_body(concurrency::streams::bytestream::open_istream(std::move(body_text)), length, _XPLATSTR(
"application/json"));
591 void set_body(std::vector<unsigned char> &&body_data)
593 auto length = body_data.size();
594 set_body(concurrency::streams::bytestream::open_istream(std::move(body_data)), length);
605 void set_body(
const std::vector<unsigned char> &body_data)
607 set_body(concurrency::streams::bytestream::open_istream(body_data), body_data.size());
620 void set_body(
const concurrency::streams::istream &stream,
const utility::string_t &content_type = _XPLATSTR(
"application/octet-stream"))
622 _m_impl->set_body(stream, content_type);
636 void set_body(
const concurrency::streams::istream &stream, utility::size64_t content_length,
const utility::string_t &content_type = _XPLATSTR(
"application/octet-stream"))
638 _m_impl->set_body(stream, content_length, content_type);
651 concurrency::streams::istream
body()
const
653 return _m_impl->instream();
663 return pplx::create_task(_m_impl->_get_data_available()).then([resp](utility::size64_t)
mutable {
return resp; });
666 std::shared_ptr<http::details::_http_response> _get_impl()
const {
return _m_impl; }
669 void _set_server_context(std::unique_ptr<http::details::_http_server_context> server_context) { _m_impl->_set_server_context(std::move(server_context)); }
673 std::shared_ptr<http::details::_http_response> _m_impl;
686 _ASYNCRTIMP _http_request(std::unique_ptr<http::details::_http_server_context> server_context);
688 virtual ~_http_request() {}
692 uri &request_uri() {
return m_uri; }
694 _ASYNCRTIMP
uri absolute_uri()
const;
696 _ASYNCRTIMP
uri relative_uri()
const;
698 _ASYNCRTIMP
void set_request_uri(
const uri&);
704 m_cancellationToken = token;
707 _ASYNCRTIMP utility::string_t to_string()
const;
716 _ASYNCRTIMP
pplx::task<void> _reply_if_not_already(http::status_code status);
718 void set_response_stream(
const concurrency::streams::ostream &stream)
720 m_response_stream = stream;
723 void set_progress_handler(
const progress_handler &handler)
725 m_progress_handler = std::make_shared<progress_handler>(handler);
728 const concurrency::streams::ostream & _response_stream()
const {
return m_response_stream; }
730 const std::shared_ptr<progress_handler> & _progress_handler()
const {
return m_progress_handler; }
734 void _set_server_context(std::unique_ptr<http::details::_http_server_context> server_context) { m_server_context = std::move(server_context); }
736 void _set_listener_path(
const utility::string_t &path) { m_listener_path = path; }
738 void _set_base_uri(
const http::uri &base_uri) { m_base_uri = base_uri; }
748 pplx::details::atomic_long m_initiated_response;
750 std::unique_ptr<http::details::_http_server_context> m_server_context;
756 utility::string_t m_listener_path;
758 concurrency::streams::ostream m_response_stream;
760 std::shared_ptr<progress_handler> m_progress_handler;
778 : _m_impl(std::make_shared<http::details::_http_request>(
methods::GET)) {}
785 : _m_impl(std::make_shared<http::details::_http_request>(std::move(mtd))) {}
863 return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) {
return impl->extract_string(ignore_content_type); });
875 return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) {
return impl->extract_utf8string(ignore_content_type); });
887 return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) {
return impl->extract_utf16string(ignore_content_type); });
899 return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) {
return impl->_extract_json(ignore_content_type); });
909 return pplx::create_task(_m_impl->_get_data_available()).then([impl](utility::size64_t) {
return impl->_extract_vector(); });
921 void set_body(utf8string &&body_text,
const utf8string &content_type = utf8string(
"text/plain; charset=utf-8"))
923 const auto length = body_text.size();
924 _m_impl->set_body(concurrency::streams::bytestream::open_istream<std::string>(std::move(body_text)), length, content_type);
936 void set_body(
const utf8string &body_text,
const utf8string &content_type = utf8string(
"text/plain; charset=utf-8"))
938 _m_impl->set_body(concurrency::streams::bytestream::open_istream<std::string>(body_text), body_text.size(), content_type);
955 throw std::invalid_argument(
"content_type can't contain a 'charset'.");
959 auto length = utf8body.size();
960 _m_impl->set_body(concurrency::streams::bytestream::open_istream(
961 std::move(utf8body)),
977 auto length = body_text.size();
978 _m_impl->set_body(concurrency::streams::bytestream::open_istream(std::move(body_text)), length, _XPLATSTR(
"application/json"));
989 void set_body(std::vector<unsigned char> &&body_data)
991 auto length = body_data.size();
992 _m_impl->set_body(concurrency::streams::bytestream::open_istream(std::move(body_data)), length, _XPLATSTR(
"application/octet-stream"));
1003 void set_body(
const std::vector<unsigned char> &body_data)
1005 set_body(concurrency::streams::bytestream::open_istream(body_data), body_data.size());
1018 void set_body(
const concurrency::streams::istream &stream,
const utility::string_t &content_type = _XPLATSTR(
"application/octet-stream"))
1020 _m_impl->set_body(stream, content_type);
1034 void set_body(
const concurrency::streams::istream &stream, utility::size64_t content_length,
const utility::string_t &content_type = _XPLATSTR(
"application/octet-stream"))
1036 _m_impl->set_body(stream, content_length, content_type);
1049 concurrency::streams::istream
body()
const
1051 return _m_impl->instream();
1065 return _m_impl->set_response_stream(stream);
1098 return _m_impl->set_progress_handler(handler);
1128 return reply(response);
1142 pplx::task<void> reply(http::status_code status, utf8string &&body_data,
const utf8string &content_type =
"text/plain; charset=utf-8")
const
1145 response.
set_body(std::move(body_data), content_type);
1146 return reply(response);
1161 pplx::task<void> reply(http::status_code status,
const utf8string &body_data,
const utf8string &content_type =
"text/plain; charset=utf-8")
const
1164 response.
set_body(body_data, content_type);
1165 return reply(response);
1183 response.
set_body(body_data, content_type);
1184 return reply(response);
1194 pplx::task<void> reply(status_code status,
const concurrency::streams::istream &
body,
const utility::string_t &content_type = _XPLATSTR(
"application/octet-stream"))
const
1197 response.
set_body(body, content_type);
1198 return reply(response);
1209 pplx::task<void> reply(status_code status,
const concurrency::streams::istream &body, utility::size64_t content_length,
const utility::string_t &content_type = _XPLATSTR(
"application/octet-stream"))
const
1212 response.
set_body(body, content_length, content_type);
1213 return reply(response);
1223 return pplx::create_task(_m_impl->_get_data_available()).then([req](utility::size64_t)
mutable {
return req; });
1232 return _m_impl->get_response();
1245 utility::string_t
to_string()
const {
return _m_impl->to_string(); }
1261 void _set_server_context(std::unique_ptr<http::details::_http_server_context> server_context) { _m_impl->_set_server_context(std::move(server_context)); }
1263 void _set_listener_path(
const utility::string_t &path) { _m_impl->_set_listener_path(path); }
1265 const std::shared_ptr<http::details::_http_request> & _get_impl()
const {
return _m_impl; }
1269 _m_impl->set_cancellation_token(token);
1274 return _m_impl->cancellation_token();
1277 void _set_base_uri(
const http::uri &base_uri)
1279 _m_impl->_set_base_uri(base_uri);
1283 friend class http::details::_http_request;
1284 friend class http::client::http_client;
1286 http_request(std::unique_ptr<http::details::_http_server_context> server_context) : _m_impl(std::make_shared<details::_http_request>(std::move(server_context))) {}
1288 std::shared_ptr<http::details::_http_request> _m_impl;
1329 return m_next_stage;
1338 return this->shared_from_this();
1344 void set_next_stage(
const std::shared_ptr<http_pipeline_stage> &next)
1346 m_next_stage = next;
1349 std::shared_ptr<http_pipeline_stage> m_next_stage;
1352 http_pipeline_stage & operator=(
const http_pipeline_stage &);
1353 http_pipeline_stage(
const http_pipeline_stage &);
1371 std::function<pplx::task<http_response>(
http_request, std::shared_ptr<http::http_pipeline_stage>)> m_handler;
1387 static std::shared_ptr<http_pipeline>
create_pipeline(
const std::shared_ptr<http_pipeline_stage> &last)
1389 return std::shared_ptr<http_pipeline>(
new http_pipeline(last));
1398 std::shared_ptr<http_pipeline_stage> first;
1401 first = (m_stages.size() > 0) ? m_stages[0] : m_last_stage;
1403 return first->propagate(request);
1410 void append(
const std::shared_ptr<http_pipeline_stage> &stage)
1414 if (m_stages.size() > 0)
1416 std::shared_ptr<http_pipeline_stage> penultimate = m_stages[m_stages.size()-1];
1417 penultimate->set_next_stage(stage);
1419 stage->set_next_stage(m_last_stage);
1421 m_stages.push_back(stage);
1430 m_last_stage = last;
1439 return m_last_stage;
1444 http_pipeline(
const std::shared_ptr<http_pipeline_stage> &last) : m_last_stage(last)
1449 std::vector<std::shared_ptr<http_pipeline_stage>> m_stages;
1454 std::shared_ptr<http_pipeline_stage> m_last_stage;
1459 http_pipeline & operator=(
const http_pipeline &);
1460 http_pipeline(
const http_pipeline &);
Predefined values for all of the standard HTTP 1.1 response status codes.
Definition: http_msg.h:82
const std::shared_ptr< http_pipeline_stage > & last_stage() const
Retrieves the last stage in this pipeline.
Definition: http_msg.h:1437
pplx::task< std::vector< unsigned char > > extract_vector() const
Extracts the body of the response message into a vector of bytes.
Definition: http_msg.h:509
A generic RAII wrapper for locks that implements the critical_section interface cpprest_synchronizati...
Definition: pplxlinux.h:264
Represents an HTTP error. This class holds an error message and an optional error code...
Definition: http_msg.h:130
const http::method & method() const
Get the method (GET/PUT/POST/DELETE) of the request message.
Definition: http_msg.h:796
pplx::task< http::http_response > content_ready() const
Signals the user (client) when all the data for this response message has been received.
Definition: http_msg.h:660
void set_request_uri(const uri &uri)
Set the underling URI of the request message.
Definition: http_msg.h:814
http_response()
Constructs a response with an empty status code, no headers, and no body.
Definition: http_msg.h:391
concurrency::streams::istream body() const
Produces a stream which the caller may use to retrieve data from an incoming request.
Definition: http_msg.h:1049
_ASYNCRTIMP std::string __cdecl utf16_to_utf8(const utf16string &w)
Converts a UTF-16 string to a UTF-8 string.
http::details::_http_server_context * _get_server_context() const
Gets the server context associated with this HTTP message.
Definition: http_msg.h:1255
const http_headers & headers() const
Gets a const reference to the headers of the response message.
Definition: http_msg.h:852
virtual _ASYNCRTIMP void _complete(utility::size64_t bodySize, const std::exception_ptr &exceptionPtr=std::exception_ptr())
Completes this message
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 ...
Definition: http_msg.h:475
Represents an HTTP response.
Definition: http_msg.h:383
void set_progress_handler(const progress_handler &handler)
Defines a callback function that will be invoked for every chunk of data uploaded or downloaded as pa...
Definition: http_msg.h:1096
Common HTTP methods.
Definition: http_msg.h:67
_ASYNCRTIMP size_t _get_content_length()
Determine the content length
pplx::task< void > reply(http::status_code status, const utf16string &body_data, const utf16string &content_type=::utility::conversions::to_utf16string("text/plain")) const
Responds to this HTTP request with a string. Assumes the character encoding of the string is UTF-16 w...
Definition: http_msg.h:1180
HTTP client handler class, used to represent an HTTP pipeline stage.
Definition: http_msg.h:1302
A flexible, protocol independent URI implementation.
Definition: base_uri.h:151
pplx::task< json::value > extract_json(bool ignore_content_type=false) const
Extracts the body of the request message into a json value, checking that the content type is applica...
Definition: http_msg.h:896
http_exception(int errorCode, const utility::string_t &whatArg)
Creates an http_exception with from a error code using the current platform error category...
Definition: http_msg.h:165
~http_request()
Destructor frees any held resources.
Definition: http_msg.h:790
http_headers & headers()
Gets a reference to the headers of the response message.
Definition: http_msg.h:843
const concurrency::streams::ostream & outstream() const
Get the stream through which the message body could be written
Definition: http_msg.h:282
const std::error_code & error_code() const
Retrieves the underlying error code causing this exception.
Definition: http_msg.h:206
Definition: http_msg.h:1358
http_exception(const utility::string_t &whatArg)
Creates an http_exception with just a string message and no error code.
Definition: http_msg.h:138
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 sta...
Definition: http_msg.h:428
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...
Definition: http_msg.h:463
pplx::task< std::vector< unsigned char > > extract_vector() const
Extract the body of the response message into a vector of bytes. Extracting a vector can be done on ...
Definition: http_msg.h:906
void set_status_code(http::status_code code) const
Sets the status code of the response message.
Definition: http_msg.h:414
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37
pplx::task< void > reply(status_code status, const concurrency::streams::istream &body, const utility::string_t &content_type=_XPLATSTR("application/octet-stream")) const
Responds to this HTTP request.
Definition: http_msg.h:1194
pplx::task_completion_event< utility::size64_t > m_data_available
The TCE is used to signal the availability of the message body.
Definition: http_msg.h:331
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.
Definition: http_msg.h:524
virtual pplx::task< http_response > propagate(http_request request)=0
Runs this stage against the given request and passes onto the next stage.
const http_headers & headers() const
Gets a const reference to the headers of the response message.
Definition: http_msg.h:443
HTTP client class, used to maintain a connection to an HTTP service for an extended session...
Definition: http_client.h:383
pplx::task< void > reply(status_code status, const concurrency::streams::istream &body, utility::size64_t content_length, const utility::string_t &content_type=_XPLATSTR("application/octet-stream")) const
Responds to this HTTP request.
Definition: http_msg.h:1209
std::shared_ptr< http_pipeline_stage > current_stage()
Gets a shared pointer to this pipeline stage.
Definition: http_msg.h:1336
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 sta...
Definition: http_msg.h:421
static std::shared_ptr< http_pipeline > create_pipeline(const std::shared_ptr< http_pipeline_stage > &last)
Create an http pipeline that consists of a linear chain of stages
Definition: http_msg.h:1387
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 al...
Definition: http_msg.h:1003
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.
Definition: http_msg.h:1245
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.
Definition: http_msg.h:553
Base class for HTTP messages. This class is to store common functionality so it isn't duplicated on b...
Definition: http_msg.h:224
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.
Definition: http_msg.h:936
pplx::task< void > reply(http::status_code status, utf8string &&body_data, const utf8string &content_type="text/plain; charset=utf-8") const
Definition: http_msg.h:1142
uri absolute_uri() const
Get an absolute URI with scheme, host, port, path, query, and fragment part of the request message...
Definition: http_msg.h:834
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 ...
Definition: http_msg.h:576
_ASYNCRTIMP utility::string_t serialize() const
Serializes the current JSON value to a C++ string.
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.
Definition: http_msg.h:921
void set_method(const http::method &method) const
Get the method (GET/PUT/POST/DELETE) of the request message.
Definition: http_msg.h:802
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.
Definition: http_msg.h:539
pplx::task< utf8string > extract_utf8string(bool ignore_content_type=false)
Extract the body of the request message as a UTF-8 string value, checking that the content type is a ...
Definition: http_msg.h:872
utility::string_t method
Predefined method strings for the standard HTTP methods mentioned in the HTTP 1.1 specification...
Definition: http_msg.h:62
Definition: http_msg.h:1379
pplx::task< utf16string > extract_utf16string(bool ignore_content_type=false)
Extract the body of the request message as a UTF-16 string value, checking that the content type is a...
Definition: http_msg.h:884
static http_request _create_request(std::unique_ptr< http::details::_http_server_context > server_context)
These are used for the initial creation of the HTTP request.
Definition: http_msg.h:1260
void append(const std::shared_ptr< http_pipeline_stage > &stage)
Adds an HTTP pipeline stage to the pipeline.
Definition: http_msg.h:1410
const std::shared_ptr< http_pipeline_stage > & next_stage() const
Gets the next stage in the pipeline.
Definition: http_msg.h:1327
const uri & request_uri() const
Get the underling URI of the request message.
Definition: http_msg.h:808
concurrency::streams::istream m_inStream
Stream to read the message body. By default this is an invalid stream. The user could set the instrea...
Definition: http_msg.h:317
_ASYNCRTIMP utf16string __cdecl to_utf16string(const std::string &value)
Converts to a UTF-16 from string.
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...
Definition: http_msg.h:636
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...
Definition: http_msg.h:1018
utility::string_t parse_and_check_content_type(bool ignore_content_type, const std::function< bool(const utility::string_t &)> &check_content_type)
Helper function for extract functions. Parses the Content-Type header and check to make sure it match...
const char * what() const CPPREST_NOEXCEPT
Gets a string identifying the cause of the exception.
Definition: http_msg.h:197
Internal representation of an HTTP response.
Definition: http_msg.h:349
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: pplxtasks.h:176
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 applic...
Definition: http_msg.h:499
http_exception(int errorCode, const std::error_category &cat)
Creates an http_exception with from a error code and category. The message of the error code will be ...
Definition: http_msg.h:188
Definition: http_msg.h:108
The cancellation_token class represents the ability to determine whether some operation has been requ...
Definition: pplxcancellation_token.h:712
Recursive mutex
Definition: pplxlinux.h:196
concurrency::streams::istream body() const
Produces a stream which the caller may use to retrieve data from an incoming request.
Definition: http_msg.h:651
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...
Definition: http_msg.h:1034
pplx::task< http_response > propagate(http_request request)
Initiate an http request into the pipeline
Definition: http_msg.h:1396
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...
Definition: http_msg.h:620
A JSON value represented as a C++ class.
Definition: json.h:83
void set_outstream(const concurrency::streams::ostream &outstream, bool is_default)
Set the stream through which the message body could be written
Definition: http_msg.h:277
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.
Definition: http_msg.h:951
pplx::task< http_request > content_ready() const
Signals the user (listener) when all the data for this request message has been received.
Definition: http_msg.h:1220
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: pplxtasks.h:4173
http_request(http::method mtd)
Constructs a new HTTP request with the given request method.
Definition: http_msg.h:784
http::status_code status_code() const
Gets the status code of the response message.
Definition: http_msg.h:405
http_response(http::status_code code)
Constructs a response with given status code, no headers, and no body.
Definition: http_msg.h:398
http_exception(int errorCode)
Creates an http_exception with from a error code using the current platform error category...
Definition: http_msg.h:154
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 ...
Definition: http_msg.h:974
pplx::task< void > reply(http::status_code status, const utf8string &body_data, const utf8string &content_type="text/plain; charset=utf-8") const
Responds to this HTTP request with a string. Assumes the character encoding of the string is UTF-8...
Definition: http_msg.h:1161
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 al...
Definition: http_msg.h:989
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 al...
Definition: http_msg.h:591
Internal representation of an HTTP request message.
Definition: http_msg.h:680
http_request()
Constructs a new HTTP request with the 'GET' method.
Definition: http_msg.h:777
Represents an HTTP request.
Definition: http_msg.h:771
uri relative_uri() const
Gets a reference the URI path, query, and fragment part of this request message. This will be appende...
Definition: http_msg.h:825
virtual pplx::task< http_response > propagate(http_request request) override
Runs this stage against the given request and passes onto the next stage.
Definition: http_msg.h:1365
pplx::task< http_response > get_response() const
Gets a task representing the response that will eventually be sent.
Definition: http_msg.h:1230
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.
Definition: http_msg.h:455
pplx::task< void > reply(http::status_code status) const
Asynchronously responses to this HTTP request.
Definition: http_msg.h:1113
_ASYNCRTIMP void _prepare_to_receive_data()
Prepare the message with an output stream to receive network data
concurrency::streams::ostream m_outStream
stream to write the msg body By default this is an invalid stream. The user could set this on the res...
Definition: http_msg.h:325
Builder for constructing URIs incrementally.
Definition: uri_builder.h:40
const concurrency::streams::istream & instream() const
Get the stream through which the message body could be read
Definition: http_msg.h:272
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 al...
Definition: http_msg.h:605
pplx::task< void > reply(http::status_code status, const json::value &body_data) const
Responds to this HTTP request.
Definition: http_msg.h:1124
void set_last_stage(const std::shared_ptr< http_pipeline_stage > &last)
Sets the last stage of the pipeline.
Definition: http_msg.h:1428
http_headers & headers()
Gets the headers of the response message.
Definition: http_msg.h:437
pplx::task< utility::string_t > extract_string(bool ignore_content_type=false)
Extract the body of the request message as a string value, checking that the content type is a MIME t...
Definition: http_msg.h:860
Base structure for associating internal server information with an HTTP request/response.
Definition: http_msg.h:338
_ASYNCRTIMP std::string __cdecl to_utf8string(std::string value)
Converts to a UTF-8 string.
Various utilities for string conversions and date and time manipulation.
Definition: asyncrt_utils.h:50
void set_response_stream(const concurrency::streams::ostream &stream)
Defines a stream that will be relied on to hold the body of the HTTP response message that results fr...
Definition: http_msg.h:1063
pplx::task< void > _reply_if_not_already(status_code status)
Sends a response if one has not already been sent.
Definition: http_msg.h:1250
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...
Definition: http_msg.h:487
pplx::task< void > reply(const http_response &response) const
Asynchronously responses to this HTTP request.
Definition: http_msg.h:1106
direction
Enumeration used to denote the direction of a message: a request with a body is an upload...
Definition: http_msg.h:99
void set_instream(const concurrency::streams::istream &instream)
Set the stream through which the message body could be read
Definition: http_msg.h:267