C++ Actor Framework 1.0.0
Loading...
Searching...
No Matches
caf::net::http::responder Class Reference

Responds to an HTTP request at the server. More...

#include <responder.hpp>

Classes

class  promise
 Allows users to respond to an incoming HTTP request at some later time. More...
 
class  promise_state
 Implementation detail for promise. More...
 

Public Member Functions

 responder (const request_header *hdr, const_byte_span body, http::router *router)
 
 responder (const responder &) noexcept=default
 
responderoperator= (const responder &) noexcept=default
 
const request_headerheader () const noexcept
 Returns the HTTP header for the responder.
 
const_byte_span body () const noexcept
 Returns the HTTP body (payload) for the responder.
 
const_byte_span payload () const noexcept
 Returns the HTTP body (payload) for the responder.
 
http::routerrouter () const noexcept
 Returns the router that has created this responder.
 
actor_shellself ()
 Returns the actor_shell object from the router for interacting with actors in the system.
 
lower_layer::server * down ()
 Returns a pointer to the HTTP layer.
 
void respond (status code)
 Sends an HTTP response that only consists of a header with a status code such as status::no_content.
 
void respond (status code, std::string_view content_type, const_byte_span content)
 Sends an HTTP response message to the client.
 
void respond (status code, std::string_view content_type, std::string_view content)
 Sends an HTTP response message to the client.
 
void respond (status code, const error &what)
 Sends an HTTP response message with an error to the client.
 
void begin_header (status code)
 Starts writing an HTTP header.
 
void add_header_field (std::string_view key, std::string_view val)
 Adds a header field.
 
bool end_header ()
 Seals the header and transports it to the client.
 
bool send_payload (const_byte_span bytes)
 Sends the payload after the header.
 
bool send_chunk (const_byte_span bytes)
 Sends a chunk of data if the full payload is unknown when starting to send.
 
bool send_end_of_chunks ()
 Sends the last chunk, completing a chunked payload.
 
request to_request () &&
 Converts a responder to a request for processing the HTTP request asynchronously.
 
promise to_promise () &&
 Converts the responder to a promise object for responding to the HTTP request at some later time but from the same socket_manager.
 

Detailed Description

Responds to an HTTP request at the server.

Provides functions for accessing the HTTP client request and for writing the HTTP response.

This class has a similar API to request, but is used at the server directly. While a request is meant to handled outside of the server by eventually fulfilling the response promise, a responder must generate the response immediately.

Member Function Documentation

◆ add_header_field()

void caf::net::http::responder::add_header_field ( std::string_view key,
std::string_view val )

Adds a header field.

Users may only call this function between begin_header and end_header.

◆ body()

const_byte_span caf::net::http::responder::body ( ) const
noexcept

Returns the HTTP body (payload) for the responder.

Precondition
valid()

◆ header()

const request_header & caf::net::http::responder::header ( ) const
noexcept

Returns the HTTP header for the responder.

Precondition
valid()

◆ payload()

const_byte_span caf::net::http::responder::payload ( ) const
noexcept

Returns the HTTP body (payload) for the responder.

Precondition
valid()

◆ respond() [1/3]

void caf::net::http::responder::respond ( status code,
const error & what )

Sends an HTTP response message with an error to the client.

Converts what to a string representation and then transfers this description to the client.

◆ respond() [2/3]

void caf::net::http::responder::respond ( status code,
std::string_view content_type,
const_byte_span content )

Sends an HTTP response message to the client.

Automatically sets the Content-Type and Content-Length header fields.

Precondition
valid()

◆ respond() [3/3]

void caf::net::http::responder::respond ( status code,
std::string_view content_type,
std::string_view content )

Sends an HTTP response message to the client.

Automatically sets the Content-Type and Content-Length header fields.

Precondition
valid()

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