userver: server::http::HttpResponse Class Reference
Loading...
Searching...
No Matches
server::http::HttpResponse Class Referencefinal

#include <userver/server/http/http_response.hpp>

Detailed Description

HTTP Response data.

Definition at line 44 of file http_response.hpp.

+ Inheritance diagram for server::http::HttpResponse:

Public Types

using HeadersMap = ::http::headers::HeaderMap
 
using HeadersMapKeys = decltype(utils::impl::MakeKeysView(HeadersMap()))
 
using CookiesMap = Cookie::CookiesMap
 
using CookiesMapKeys = decltype(utils::impl::MakeKeysView(CookiesMap()))
 
using Queue = concurrent::StringStreamQueue
 
using Producer = std::variant<std::monostate, Queue::Producer, impl::Http2StreamEventProducer>
 

Public Member Functions

bool SetHeader (std::string name, std::string value)
 Add a new response header or rewrite an existing one.
 
bool SetHeader (std::string_view name, std::string value)
 Add a new response header or rewrite an existing one.
 
bool SetHeader (const ::http::headers::PredefinedHeader &header, std::string value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void SetContentType (const ::http::ContentType &type)
 Add or rewrite the Content-Type header.
 
void SetContentEncoding (std::string encoding)
 Add or rewrite the Content-Encoding header.
 
bool SetStatus (HttpStatus status)
 Set the HTTP response status code.
 
bool ClearHeaders ()
 Remove all headers from response.
 
void SetCookie (Cookie cookie)
 Sets a cookie if it was not set before.
 
void ClearCookies ()
 Remove all cookies from response.
 
HttpStatus GetStatus () const
 
HeadersMapKeys GetHeaderNames () const
 
const std::string & GetHeader (std::string_view header_name) const
 
const std::string & GetHeader (const ::http::headers::PredefinedHeader &header_name) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool HasHeader (std::string_view header_name) const
 
bool HasHeader (const ::http::headers::PredefinedHeader &header_name) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
CookiesMapKeys GetCookieNames () const
 
const CookieGetCookie (std::string_view cookie_name) const
 
void SetStatusServiceUnavailable () override
 
void SetStatusOk () override
 
void SetStatusNotFound () override
 
bool WaitForHeadersEnd () override
 
void SetHeadersEnd () override
 
void SetStreamBody ()
 
bool IsBodyStreamed () const override
 
Producer GetBodyProducer ()
 
void SetData (std::string data)
 
const std::string & GetData () const
 
std::string && ExtractData ()
 

Protected Member Functions

void SetSent (std::size_t bytes_sent, std::chrono::steady_clock::time_point sent_time)
 

Member Typedef Documentation

◆ CookiesMap

using server::http::HttpResponse::CookiesMap = Cookie::CookiesMap

Definition at line 50 of file http_response.hpp.

◆ CookiesMapKeys

using server::http::HttpResponse::CookiesMapKeys = decltype(utils::impl::MakeKeysView(CookiesMap()))

Definition at line 52 of file http_response.hpp.

◆ HeadersMap

◆ HeadersMapKeys

using server::http::HttpResponse::HeadersMapKeys = decltype(utils::impl::MakeKeysView(HeadersMap()))

Definition at line 48 of file http_response.hpp.

◆ Producer

using server::http::HttpResponse::Producer = std::variant<std::monostate, Queue::Producer, impl::Http2StreamEventProducer>

Definition at line 140 of file http_response.hpp.

◆ Queue

Member Function Documentation

◆ ClearHeaders()

bool server::http::HttpResponse::ClearHeaders ( )

Remove all headers from response.

Returns
true if the headers were cleared. Returns false if headers were already sent for stream'ed response and the headers were not cleared.

◆ ExtractData()

std::string && server::request::ResponseBase::ExtractData ( )
inlineinherited

Definition at line 84 of file response_base.hpp.

◆ GetCookie()

const Cookie & server::http::HttpResponse::GetCookie ( std::string_view cookie_name) const
Returns
Value of the cookie with case sensitive name cookie_name, or an empty string if no such cookie exists.

◆ GetCookieNames()

CookiesMapKeys server::http::HttpResponse::GetCookieNames ( ) const
Returns
List of cookies names.

◆ GetData()

const std::string & server::request::ResponseBase::GetData ( ) const
inlineinherited

Definition at line 83 of file response_base.hpp.

◆ GetHeader()

const std::string & server::http::HttpResponse::GetHeader ( std::string_view header_name) const
Returns
Value of the header with case insensitive name header_name, or an empty string if no such header.

◆ GetHeaderNames()

HeadersMapKeys server::http::HttpResponse::GetHeaderNames ( ) const
Returns
List of HTTP headers names.

◆ GetStatus()

HttpStatus server::http::HttpResponse::GetStatus ( ) const
inline
Returns
HTTP response status

Definition at line 103 of file http_response.hpp.

◆ HasHeader()

bool server::http::HttpResponse::HasHeader ( std::string_view header_name) const
Returns
true if header with case insensitive name header_name exists, false otherwise.

◆ IsBodyStreamed()

bool server::http::HttpResponse::IsBodyStreamed ( ) const
overridevirtual

◆ SetHeader() [1/2]

bool server::http::HttpResponse::SetHeader ( std::string name,
std::string value )

Add a new response header or rewrite an existing one.

Returns
true if the header was set. Returns false if headers were already sent for stream'ed response and the new header was not set.

◆ SetHeader() [2/2]

bool server::http::HttpResponse::SetHeader ( std::string_view name,
std::string value )

Add a new response header or rewrite an existing one.

Returns
true if the header was set. Returns false if headers were already sent for stream'ed response and the new header was not set.

◆ SetHeadersEnd()

void server::http::HttpResponse::SetHeadersEnd ( )
overridevirtual

◆ SetStatus()

bool server::http::HttpResponse::SetStatus ( HttpStatus status)

Set the HTTP response status code.

Returns
true if the status was set. Returns false if headers were already sent for stream'ed response and the new status was not set.
Examples
samples/multipart_service/service.cpp.

◆ SetStatusNotFound()

void server::http::HttpResponse::SetStatusNotFound ( )
inlineoverride

Definition at line 134 of file http_response.hpp.

◆ SetStatusOk()

void server::http::HttpResponse::SetStatusOk ( )
inlineoverride

Definition at line 133 of file http_response.hpp.

◆ SetStatusServiceUnavailable()

void server::http::HttpResponse::SetStatusServiceUnavailable ( )
inlineoverride

Definition at line 132 of file http_response.hpp.

◆ WaitForHeadersEnd()

bool server::http::HttpResponse::WaitForHeadersEnd ( )
overridevirtual

Friends And Related Symbol Documentation

◆ Http2ResponseWriter

friend class Http2ResponseWriter
friend

Definition at line 148 of file http_response.hpp.


The documentation for this class was generated from the following file: