# Response.hpp
This File On Github
Ask A Question
API: latest
module: oatpp
#include "oatpp/web/protocol/http/incoming/Response.hpp"
# Response
Class http::incoming::Response AKA IncomingResponse represents server's incoming response
namespace oatpp { namespace web { namespace protocol { namespace http { namespace incoming {
class Response : public oatpp::base::Countable {}
}}}}}
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | Response | Constructor. |
std::shared_ptr<Response> | createShared | Create shared Response. |
v_int32 | getStatusCode | Get http status code. |
oatpp::String | getStatusDescription | Get http status description. |
const http::Headers& | getHeaders | Get response http headers as oatpp::web::protocol::http::Headers. |
void | putHeader | Add http header. |
bool | putHeaderIfNotExists | Add http header if not already exists. |
bool | putOrReplaceHeader | Replaces or adds header. |
bool | putOrReplaceHeader_Unsafe | Replaces or adds header. |
void | putHeader_Unsafe | Add http header. |
bool | putHeaderIfNotExists_Unsafe | Add http header if not already exists. |
oatpp::String | getHeader | Get header value |
void | putBundleData | Put data to bundle. |
WrapperType | getBundleData | Get data from bundle by key. |
const data::Bundle& | getBundle | Get bundle object. |
std::shared_ptr<data::stream::InputStream> | getBodyStream | Get raw body stream. |
std::shared_ptr<const http::incoming::BodyDecoder> | getBodyDecoder | Get body decoder configured for this response. |
void | transferBody | Transfer body. |
void | transferBodyToStream | Decode and transfer body to toStream. |
oatpp::String | readBodyToString | Decode and read body to oatpp::String. |
Wrapper | readBodyToDto | Read body stream, decode, and deserialize it as DTO Object (see Data Transfer Object (DTO)). |
async::CoroutineStarter | transferBodyAsync | Transfer body in Asynchronous manner. |
oatpp::async::CoroutineStarter | transferBodyToStreamAsync | Same as Response::readBodyToDto() but Async. |
oatpp::async::CoroutineStarterForResult<const oatpp::String&> | readBodyToStringAsync | Same as Response::readBodyToString() but Async. |
oatpp::async::CoroutineStarterForResult<const Wrapper&> | readBodyToDtoAsync | Same as Response::readBodyToDto() but Async. |
# Response::Response
Constructor.
- @param statusCode - http status code.
- @param statusDescription - http status description.
- @param headers - oatpp::web::protocol::http::Headers.
- @param bodyStream - oatpp::data::stream::InputStream.
- @param bodyDecoder - oatpp::web::protocol::http::incoming::BodyDecoder.
Response(v_int32 statusCode,
const oatpp::String& statusDescription,
const http::Headers& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<const http::incoming::BodyDecoder>& bodyDecoder)
# Response::createShared
Create shared Response.
- @param statusCode - http status code.
- @param statusDescription - http status description.
- @param headers - oatpp::web::protocol::http::Headers.
- @param bodyStream - oatpp::data::stream::InputStream.
- @param bodyDecoder - oatpp::web::protocol::http::incoming::BodyDecoder.
- @return -
std::shared_ptr
to Response.
static std::shared_ptr<Response> createShared(v_int32 statusCode,
const oatpp::String& statusDescription,
const http::Headers& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<const http::incoming::BodyDecoder>& bodyDecoder)
# Response::getStatusCode
Get http status code.
- @return - http status code.
v_int32 getStatusCode() const
# Response::getStatusDescription
Get http status description.
- @return - http status description.
oatpp::String getStatusDescription() const
# Response::getHeaders
Get response http headers as oatpp::web::protocol::http::Headers.
- @return - response http headers as oatpp::web::protocol::http::Headers.
const http::Headers& getHeaders() const
# Response::putHeader
Add http header.
- @param key - oatpp::String.
- @param value - oatpp::String.
void putHeader(const oatpp::String& key, const oatpp::String& value)
# Response::putHeaderIfNotExists
Add http header if not already exists.
- @param key - oatpp::String.
- @param value - oatpp::String.
- @return -
true
if header was added.
bool putHeaderIfNotExists(const oatpp::String& key, const oatpp::String& value)
# Response::putOrReplaceHeader
Replaces or adds header.
- @param key - oatpp::String.
- @param value - oatpp::String.
- @return -
true
if header was replaces,false
if header was added.
bool putOrReplaceHeader(const oatpp::String& key, const oatpp::String& value)
# Response::putOrReplaceHeader_Unsafe
Replaces or adds header.
- @param key - oatpp::data::share::StringKeyLabelCI.
- @param value - oatpp::data::share::StringKeyLabel.
- @return -
true
if header was replaces,false
if header was added.
bool putOrReplaceHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value)
# Response::putHeader_Unsafe
Add http header.
- @param key - oatpp::data::share::StringKeyLabelCI.
- @param value - oatpp::data::share::StringKeyLabel.
void putHeader_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value)
# Response::putHeaderIfNotExists_Unsafe
Add http header if not already exists.
- @param key - oatpp::data::share::StringKeyLabelCI.
- @param value - oatpp::data::share::StringKeyLabel.
- @return -
true
if header was added.
bool putHeaderIfNotExists_Unsafe(const oatpp::data::share::StringKeyLabelCI& key, const oatpp::data::share::StringKeyLabel& value)
# Response::getHeader
Get header value
- @param headerName - oatpp::data::share::StringKeyLabelCI.
- @return - oatpp::String.
oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI& headerName) const
# Response::putBundleData
Put data to bundle.
- @param key
- @param polymorph
void putBundleData(const oatpp::String& key, const oatpp::Void& polymorph)
# Response::getBundleData
Get data from bundle by key.
- @tparam WrapperType
- @param key
- @return
template<typename WrapperType>
WrapperType getBundleData(const oatpp::String& key) const
# Response::getBundle
Get bundle object.
- @return
const data::Bundle& getBundle() const
# Response::getBodyStream
Get raw body stream.
- @return - raw body stream as oatpp::data::stream::InputStream.
std::shared_ptr<data::stream::InputStream> getBodyStream() const
# Response::getBodyDecoder
Get body decoder configured for this response.
std::shared_ptr<const http::incoming::BodyDecoder> getBodyDecoder() const
# Response::transferBody
Transfer body.
Read body chunk by chunk and pass chunks to the writeCallback
.
- @param writeCallback - oatpp::data::stream::WriteCallback.
void transferBody(const base::ObjectHandle<data::stream::WriteCallback>& writeCallback) const
# Response::transferBodyToStream
Decode and transfer body to toStream. Use case example - stream huge body directly to file using relatively small buffer.
- @param toStream - pointer to oatpp::data::stream::OutputStream.
void transferBodyToStream(const base::ObjectHandle<data::stream::OutputStream>& toStream) const
# Response::readBodyToString
Decode and read body to oatpp::String.
- @return - oatpp::String.
oatpp::String readBodyToString() const
# Response::readBodyToDto
Read body stream, decode, and deserialize it as DTO Object (see Data Transfer Object (DTO)).
- @tparam Wrapper - ObjectWrapper type.
- @param objectMapper -
std::shared_ptr
to oatpp::data::mapping::ObjectMapper. - @return - deserialized DTO object.
template<class Wrapper>
Wrapper readBodyToDto(const base::ObjectHandle<data::mapping::ObjectMapper>& objectMapper) const
# Response::transferBodyAsync
Transfer body in Asynchronous manner.
Read body chunk by chunk and pass chunks to the writeCallback
.
- @param writeCallback -
std::shared_ptr
to oatpp::data::stream::WriteCallback. - @return - oatpp::async::CoroutineStarter.
async::CoroutineStarter transferBodyAsync(const std::shared_ptr<data::stream::WriteCallback>& writeCallback) const
# Response::transferBodyToStreamAsync
Same as Response::readBodyToDto() but Async.
- @param toStream -
std::shared_ptr
to oatpp::data::stream::OutputStream. - @return - oatpp::async::CoroutineStarter.
oatpp::async::CoroutineStarter transferBodyToStreamAsync(const std::shared_ptr<data::stream::OutputStream>& toStream) const
# Response::readBodyToStringAsync
Same as Response::readBodyToString() but Async.
- @return - oatpp::async::CoroutineStarterForResult.
oatpp::async::CoroutineStarterForResult<const oatpp::String&> readBodyToStringAsync() const
# Response::readBodyToDtoAsync
Same as Response::readBodyToDto() but Async.
- @tparam Wrapper - ObjectWrapper type.
- @param objectMapper -
std::shared_ptr
to oatpp::data::mapping::ObjectMapper. - @return - oatpp::async::CoroutineStarterForResult.
template<class Wrapper>
oatpp::async::CoroutineStarterForResult<const Wrapper&>
readBodyToDtoAsync(const std::shared_ptr<data::mapping::ObjectMapper>& objectMapper) const