Template Struct context_common

Inheritance Relationships

Derived Types

Struct Documentation

template<typename AuxT, typename RequestT>
struct udho::detail::context_common

Subclassed by udho::context< AuxT, RequestT, ShadowT >, udho::context< AuxT, RequestT, void >

Public Types

typedef RequestT request_type
typedef context_common<AuxT, request_type> self_type
typedef detail::context_impl<request_type> impl_type
typedef boost::shared_ptr<impl_type> pimple_type
typedef udho::forms::form_<RequestT> form_type
typedef udho::cookies_<RequestT> cookies_type
typedef udho::forms::query_ query_parser_type

Public Functions

template<typename C>
context_common(AuxT &aux, const RequestT &request, const C&)
template<typename ShadowT>
context_common(self_type &other)
interaction_ &interaction()
const request_type &request() const

returns the boost beast HTTP request

template<class Body, class Fields>
void patch(boost::beast::http::message<false, Body, Fields> &res) const

patches the response with the headers added in the context from inside the callable

form_type &form()

returns the form handler object.

See

udho::form_

See

udho::urlencoded_form

See

udho::multipart_form

cookies_type &cookies()

accesses the HTTP cookies

See

udho::cookies_

operator request_type() const

conversion operator to convert to the corresponding beast request type

template<udho::logging::status Status>
void log(const udho::logging::message<Status> &msg) const

Logs a message to the logger attached with the server. A logging message can be passed to the log method or the operator<< can be used to log a message.

ctx << udho::logging::messages::formatted::debug("data", "testing log functionality of %1% Hi %2%") % "Neel Basu" % 42;
ctx << udho::logging::messages::formatted::info("data", "testing log functionality of %1% Hi %2%") % "Neel Basu" % 42;
ctx << udho::logging::messages::formatted::warning("data", "testing log functionality of %1% Hi %2%") % "Neel Basu" % 42;
ctx << udho::logging::messages::formatted::error("data", "testing log functionality of %1% Hi %2%") % "Neel Basu" % 42;
See

udho::logging::message

template<typename AttachmentT>
void attach(AttachmentT &attachment)

attaches a context with its server counter part

AuxT &aux()

returns a reference to the bridge between the callable and the server

void respond(udho::defs::response_type &response)

respond with a http status. The responded output will be put inside a beast HTTP response object and a content type header of type mime will be attached

template<typename OutputT>
void respond(const OutputT &output, const std::string &mime)

the responded output will be put inside a beast HTTP response object and a content type header of type mime will be attached

template<typename OutputT>
void respond(boost::beast::http::status s, const OutputT &output, const std::string &mime)

respond with a http status. The responded output will be put inside a beast HTTP response object and a content type header of type mime will be attached

void status(boost::beast::http::status s)

set a status code for the HTTP response

std::string target() const

target of the HTTP request including the ? if the request includes get parameters

// https://localhost/user/profile?id=245
ctx.target() // /user/profile?id=245

std::string path() const

path of the HTTP request before ? if any

// https://localhost/user/profile?id=245
ctx.path() // /user/profile

const query_parser_type &query() const

The get query of the HTTP request.

if(!ctx.query().has("type") || ctx.query().field<std::string>("type") == "json"){
    // respond with JSON content
}else if(ctx.query().field<std::string>("type") == "xml")
    // respond with xml content
}
See

udho::urlencoded_form

void clear()
void reroute(const std::string &path)

Internally reroute an HTTP request to another request

bool rerouted() const

check whether this is a rerouted request or not

std::string alt_path() const
std::string render(const std::string &path) const

render a file in path

template<typename ...DataT>
std::string render(const std::string &path, const DataT&... data) const

render a template in path

void push(const udho::detail::route &r)
udho::detail::route top() const
udho::detail::route pop()
std::size_t reroutes() const
detail::client_connection_wrapper<self_type> client(udho::config<udho::client_options> options = udho::config<udho::client_options>())
boost::asio::io_service &io()

Public Members

pimple_type _pimpl
AuxT &_aux