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

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

Detailed Description

HTTP Response data.

Definition at line 74 of file http_response.hpp.

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()))

Public Member Functions

 HttpResponse (const HttpResponse &)=delete
 HttpResponse (HttpResponse &&)=delete
void SetData (std::string data)
void SetSharedData (std::shared_ptr< const std::string > data)
 Sets response body without copying, keeping data alive. Useful for serving cached static content.
const std::string & GetData () const
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) noexcept
 Set the HTTP response status code.
bool ClearUserHeaders ()
 Remove all headers from response, except system headers.
void SetCookie (Cookie cookie)
 Sets a cookie if it was not set before.
void ClearCookies ()
 Remove all cookies from response.
HttpStatus GetStatus () const noexcept
HeadersMapKeys GetSystemHeaderNames () const
HeadersMapKeys GetUserHeaderNames () 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 Cookie & GetCookie (std::string_view cookie_name) const
void SetStatusServiceUnavailable ()
void SetStatusOk ()
void SetStatusNotFound ()
bool WaitForHeadersEnd ()
void SetHeadersEnd ()
bool IsHeadersEnd () const noexcept
bool IsBodyStreamed () const noexcept
bool IsSent () const noexcept

Protected Member Functions

 HttpResponse (const HttpRequest &request, request::ResponseDataAccounter &data_accounter)
 HttpResponse (const HttpRequest &request, request::ResponseDataAccounter &data_accounter, std::chrono::steady_clock::time_point now, utils::StrCaseHash hasher)

Member Typedef Documentation

◆ CookiesMap

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

Definition at line 83 of file http_response.hpp.

◆ CookiesMapKeys

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

Definition at line 85 of file http_response.hpp.

◆ HeadersMap

using server::http::HttpResponse::HeadersMap = ::http::headers::HeaderMap

Definition at line 79 of file http_response.hpp.

◆ HeadersMapKeys

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

Definition at line 81 of file http_response.hpp.

Member Function Documentation

◆ ClearUserHeaders()

bool server::http::HttpResponse::ClearUserHeaders ( )

Remove all headers from response, except system headers.

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

◆ 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.

◆ 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.

◆ GetStatus()

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

Definition at line 131 of file http_response.hpp.

◆ GetSystemHeaderNames()

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

◆ GetUserHeaderNames()

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

◆ 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
inlinenodiscardnoexcept

Definition at line 168 of file http_response.hpp.

◆ IsHeadersEnd()

bool server::http::HttpResponse::IsHeadersEnd ( ) const
inlinenodiscardnoexcept
Returns
true if response headers were committed and cannot be changed.

Definition at line 166 of file http_response.hpp.

◆ IsSent()

bool server::http::HttpResponse::IsSent ( ) const
inlinenodiscardnoexcept

Definition at line 170 of file http_response.hpp.

◆ 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, or the header overrides system header.

◆ 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, or the header overrides system header.

◆ SetStatus()

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

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/main.cpp.

◆ SetStatusNotFound()

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

Definition at line 160 of file http_response.hpp.

◆ SetStatusOk()

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

Definition at line 159 of file http_response.hpp.

◆ SetStatusServiceUnavailable()

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

Definition at line 158 of file http_response.hpp.

◆ Http2ResponseWriter

friend class Http2ResponseWriter
friend

Definition at line 184 of file http_response.hpp.

◆ HttpResponseImpl

friend class HttpResponseImpl
friend

Definition at line 183 of file http_response.hpp.


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