roar
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Roar::Session::SendIntermediate< BodyT > Class Template Reference

Helper class to prepare and send a response. More...

#include <session.hpp>

Collaboration diagram for Roar::Session::SendIntermediate< BodyT >:

Public Member Functions

template<typename... Forwards, typename RequestBodyT >
 SendIntermediate (Session &session, Request< RequestBodyT > const &req, Forwards &&... forwards)
 
 SendIntermediate (Session &session, boost::beast::http::response< BodyT > res)
 
 SendIntermediate (Session &session, Response< BodyT > &&res)
 
 SendIntermediate (Session &session)
 
 SendIntermediate (SendIntermediate &&)=default
 
 SendIntermediate (SendIntermediate const &)=delete
 
SendIntermediateoperator= (SendIntermediate &&)=default
 
SendIntermediateoperator= (SendIntermediate const &)=delete
 
SendIntermediatestatus (boost::beast::http::status status)
 Sets the response status code.
 
auto & body ()
 Retrieve the response body object.
 
template<typename T >
SendIntermediatebody (T &&toAssign)
 This function can be used to assign something to the body.
 
SendIntermediatechunked (bool activate=true)
 (De)Activate chunked encoding.
 
template<typename T >
SendIntermediatecontentType (T &&type)
 For setting of the content type.
 
template<typename T >
SendIntermediatesetHeader (boost::beast::http::field field, T &&value)
 Can be used to set a header field.
 
template<typename T >
SendIntermediateheader (boost::beast::http::field field, T &&value)
 
SendIntermediateonWriteSome (std::function< bool(std::size_t)> onChunkFunc)
 Set a callback function that is called whenever some data was written.
 
template<typename RequestBodyT2 >
SendIntermediateenableCors (Request< RequestBodyT2 > const &req, std::optional< CorsSettings > cors=std::nullopt)
 Sets cors headers.
 
SendIntermediatepreparePayload ()
 
SendIntermediatemodifyResponse (std::function< void(Response< BodyT > &)> func)
 
template<typename T = BodyT, bool OverrideSfinae = false>
std::enable_if_t< !(std::is_same_v< T, RangeFileBody >||std::is_same_v< T, boost::beast::http::empty_body >)||OverrideSfinae, CommitReturnTypecommit ()
 Sends the response and invalidates this object.
 
template<typename T = BodyT>
std::enable_if_t< std::is_same_v< T, boost::beast::http::empty_body >, CommitReturnTypecommit ()
 Sends the response and invalidates this object.
 
template<typename T = BodyT>
std::enable_if_t< std::is_same_v< T, RangeFileBody >, CommitReturnTypecommit ()
 Sends the response for range request file bodies. Sets appropriate headers.
 
SendIntermediaterejectAuthorization (std::string const &wwwAuthenticate)
 Sets WWW-Authenticate header and sets the status to unauthorized.
 
SendIntermediatekeepAlive (bool keepAlive=true)
 Set keep alive.
 
SendIntermediatesetCookie (Cookie const &cookie)
 Sets a cookie.
 
SendIntermediateuseFixedTimeout (std::chrono::milliseconds timeout)
 Set a timeout for the whole write operation.
 

Private Types

using CommitReturnType = Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< bool >, Detail::PromiseTypeBindFail< Error > >
 

Private Member Functions

void writeHeader ()
 
void writeChunk ()
 

Private Attributes

std::shared_ptr< Sessionsession_
 
Response< BodyT > response_
 
std::function< bool(std::size_t)> onChunk_
 
std::unique_ptr< promise::Promise > promise_
 
std::optional< std::chrono::milliseconds > overallTimeout_
 
std::unique_ptr< boost::beast::http::serializer< false, BodyT > > serializer_
 

Detailed Description

template<typename BodyT>
class Roar::Session::SendIntermediate< BodyT >

Helper class to prepare and send a response.

Member Typedef Documentation

◆ CommitReturnType

template<typename BodyT >
using Roar::Session::SendIntermediate< BodyT >::CommitReturnType = Detail::PromiseTypeBind<Detail::PromiseTypeBindThen<bool>, Detail::PromiseTypeBindFail<Error> >
private

Constructor & Destructor Documentation

◆ SendIntermediate() [1/6]

template<typename BodyT >
template<typename... Forwards, typename RequestBodyT >
Roar::Session::SendIntermediate< BodyT >::SendIntermediate ( Session session,
Request< RequestBodyT > const &  req,
Forwards &&...  forwards 
)
inline

◆ SendIntermediate() [2/6]

template<typename BodyT >
Roar::Session::SendIntermediate< BodyT >::SendIntermediate ( Session session,
boost::beast::http::response< BodyT >  res 
)
inline

◆ SendIntermediate() [3/6]

template<typename BodyT >
Roar::Session::SendIntermediate< BodyT >::SendIntermediate ( Session session,
Response< BodyT > &&  res 
)
inline

◆ SendIntermediate() [4/6]

template<typename BodyT >
Roar::Session::SendIntermediate< BodyT >::SendIntermediate ( Session session)
inline

◆ SendIntermediate() [5/6]

template<typename BodyT >
Roar::Session::SendIntermediate< BodyT >::SendIntermediate ( SendIntermediate< BodyT > &&  )
default

◆ SendIntermediate() [6/6]

template<typename BodyT >
Roar::Session::SendIntermediate< BodyT >::SendIntermediate ( SendIntermediate< BodyT > const &  )
delete

Member Function Documentation

◆ body() [1/2]

template<typename BodyT >
auto & Roar::Session::SendIntermediate< BodyT >::body ( )
inline

Retrieve the response body object.

Returns
auto&

◆ body() [2/2]

template<typename BodyT >
template<typename T >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::body ( T &&  toAssign)
inline

This function can be used to assign something to the body.

Template Parameters
T
Parameters
toAssign
Returns
Response& Returned for chaining.

◆ chunked()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::chunked ( bool  activate = true)
inline

(De)Activate chunked encoding.

Parameters
activate
Returns
Response& Returned for chaining.

◆ commit() [1/3]

template<typename BodyT >
template<typename T = BodyT, bool OverrideSfinae = false>
std::enable_if_t< !(std::is_same_v< T, RangeFileBody >||std::is_same_v< T, boost::beast::http::empty_body >)|| OverrideSfinae, CommitReturnType > Roar::Session::SendIntermediate< BodyT >::commit ( )
inline

Sends the response and invalidates this object.

◆ commit() [2/3]

template<typename BodyT >
template<typename T = BodyT>
std::enable_if_t< std::is_same_v< T, boost::beast::http::empty_body >, CommitReturnType > Roar::Session::SendIntermediate< BodyT >::commit ( )
inline

Sends the response and invalidates this object.

◆ commit() [3/3]

template<typename BodyT >
template<typename T = BodyT>
std::enable_if_t< std::is_same_v< T, RangeFileBody >, CommitReturnType > Roar::Session::SendIntermediate< BodyT >::commit ( )
inline

Sends the response for range request file bodies. Sets appropriate headers.

◆ contentType()

template<typename BodyT >
template<typename T >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::contentType ( T &&  type)
inline

For setting of the content type.

Parameters
type
Returns
Response& Returned for chaining.

◆ enableCors()

template<typename BodyT >
template<typename RequestBodyT2 >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::enableCors ( Request< RequestBodyT2 > const &  req,
std::optional< CorsSettings cors = std::nullopt 
)
inline

Sets cors headers.

Parameters
reqA request to base the cors headers off of.
corsA cors settings object. If not supplied, a very permissive setting is used.
Returns
Response& Returned for chaining.

◆ header()

template<typename BodyT >
template<typename T >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::header ( boost::beast::http::field  field,
T &&  value 
)
inline

◆ keepAlive()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::keepAlive ( bool  keepAlive = true)
inline

Set keep alive.

Parameters
keepAlive
Returns
SendIntermediate&

◆ modifyResponse()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::modifyResponse ( std::function< void(Response< BodyT > &)>  func)
inline

◆ onWriteSome()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::onWriteSome ( std::function< bool(std::size_t)>  onChunkFunc)
inline

Set a callback function that is called whenever some data was written.

Parameters
onChunkFuncThe function to be called. Is called with the buffer and amount of bytes transferred. Return false in this function to stop writing.
Returns
ReadIntermediate& Returns itself for chaining.

◆ operator=() [1/2]

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::operator= ( SendIntermediate< BodyT > &&  )
default

◆ operator=() [2/2]

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::operator= ( SendIntermediate< BodyT > const &  )
delete

◆ preparePayload()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::preparePayload ( )
inline

◆ rejectAuthorization()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::rejectAuthorization ( std::string const &  wwwAuthenticate)
inline

Sets WWW-Authenticate header and sets the status to unauthorized.

Parameters
wwwAuthenticateA string to be used as the value of the header. eg: "Basic realm=<realm>"

◆ setCookie()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::setCookie ( Cookie const &  cookie)
inline

Sets a cookie.

Parameters
cookieA cookie object
Returns
SendIntermediate& Returns itself for chaining.

◆ setHeader()

template<typename BodyT >
template<typename T >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::setHeader ( boost::beast::http::field  field,
T &&  value 
)
inline

Can be used to set a header field.

Returns
Response& Returned for chaining.

◆ status()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::status ( boost::beast::http::status  status)
inline

Sets the response status code.

Parameters
statusA status code.

◆ useFixedTimeout()

template<typename BodyT >
SendIntermediate & Roar::Session::SendIntermediate< BodyT >::useFixedTimeout ( std::chrono::milliseconds  timeout)
inline

Set a timeout for the whole write operation.

Parameters
timeoutThe timeout as a std::chrono::duration.
Returns
ReadIntermediate& Returns itself for chaining.

◆ writeChunk()

template<typename BodyT >
void Roar::Session::SendIntermediate< BodyT >::writeChunk ( )
inlineprivate

◆ writeHeader()

template<typename BodyT >
void Roar::Session::SendIntermediate< BodyT >::writeHeader ( )
inlineprivate

Member Data Documentation

◆ onChunk_

template<typename BodyT >
std::function<bool(std::size_t)> Roar::Session::SendIntermediate< BodyT >::onChunk_
private

◆ overallTimeout_

template<typename BodyT >
std::optional<std::chrono::milliseconds> Roar::Session::SendIntermediate< BodyT >::overallTimeout_
private

◆ promise_

template<typename BodyT >
std::unique_ptr<promise::Promise> Roar::Session::SendIntermediate< BodyT >::promise_
private

◆ response_

template<typename BodyT >
Response<BodyT> Roar::Session::SendIntermediate< BodyT >::response_
private

◆ serializer_

template<typename BodyT >
std::unique_ptr<boost::beast::http::serializer<false, BodyT> > Roar::Session::SendIntermediate< BodyT >::serializer_
private

◆ session_

template<typename BodyT >
std::shared_ptr<Session> Roar::Session::SendIntermediate< BodyT >::session_
private

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