C++ Actor Framework 0.19
|
Implements the server part for the HTTP Protocol as defined in RFC 7231. More...
#include <server.hpp>
Public Types | |
enum class | mode { read_header , read_payload , read_chunks } |
using | upper_layer_ptr = std::unique_ptr< http::upper_layer > |
Public Member Functions | |
server (upper_layer_ptr up) | |
auto & | upper_layer () noexcept |
const auto & | upper_layer () const noexcept |
size_t | max_request_size () const noexcept |
void | max_request_size (size_t value) noexcept |
multiplexer & | mpx () noexcept override |
Returns the multiplexer instance that executes this protocol stack. | |
bool | can_send_more () const noexcept override |
Queries whether the output device can accept more data straight away. | |
bool | is_reading () const noexcept override |
Queries whether the lower layer is currently reading from its input device. | |
void | write_later () override |
Triggers a write callback after the write device signals downstream capacity. | |
void | shutdown () override |
Shuts down any connection or session gracefully. | |
void | request_messages () override |
Start or re-start reading data from the client. | |
void | suspend_reading () override |
Stops reading messages until calling request_messages . | |
void | begin_header (status code) override |
Starts writing an HTTP header. | |
void | add_header_field (std::string_view key, std::string_view val) override |
Adds a header field. | |
bool | end_header () override |
Seals the header and transports it to the client. | |
bool | send_payload (const_byte_span bytes) override |
Sends the payload after the header. | |
bool | send_chunk (const_byte_span bytes) override |
Sends a chunk of data if the full payload is unknown when starting to send. | |
bool | send_end_of_chunks () override |
Sends the last chunk, completing a chunked payload. | |
void | switch_protocol (std::unique_ptr< octet_stream::upper_layer >) override |
Asks the stream to swap the HTTP layer with next after returning from consume . | |
error | start (octet_stream::lower_layer *down) override |
Initializes the upper layer. | |
void | abort (const error &reason) override |
Called by the lower layer for cleaning up any state in case of an error or when disposed. | |
void | prepare_send () override |
Gives the upper layer an opportunity to add additional data to the output buffer. | |
bool | done_sending () override |
Queries whether all pending data has been sent. | |
ptrdiff_t | consume (byte_span input, byte_span) override |
Consumes bytes from the lower layer. | |
virtual error | start (lower_layer *down)=0 |
Initializes the upper layer. | |
virtual ptrdiff_t | consume (byte_span buffer, byte_span delta)=0 |
Consumes bytes from the lower layer. | |
virtual void | prepare_send ()=0 |
Gives the upper layer an opportunity to add additional data to the output buffer. | |
virtual bool | done_sending ()=0 |
Queries whether all pending data has been sent. | |
virtual void | abort (const error &reason)=0 |
Called by the lower layer for cleaning up any state in case of an error or when disposed. | |
![]() | |
virtual void | request_messages ()=0 |
Start or re-start reading data from the client. | |
virtual void | suspend_reading ()=0 |
Stops reading messages until calling request_messages . | |
virtual void | begin_header (status code)=0 |
Starts writing an HTTP header. | |
virtual void | add_header_field (std::string_view key, std::string_view val)=0 |
Adds a header field. | |
virtual bool | end_header ()=0 |
Seals the header and transports it to the client. | |
virtual bool | send_payload (const_byte_span bytes)=0 |
Sends the payload after the header. | |
virtual bool | send_chunk (const_byte_span bytes)=0 |
Sends a chunk of data if the full payload is unknown when starting to send. | |
virtual bool | send_end_of_chunks ()=0 |
Sends the last chunk, completing a chunked payload. | |
bool | send_response (status code) |
Sends a response that only consists of a header with a status code such as status::no_content . | |
bool | send_response (status code, std::string_view content_type, const_byte_span content) |
Convenience function for sending header and payload. | |
bool | send_response (status code, std::string_view content_type, std::string_view content) |
Sends a response that only consists of a header with a status code such as status::no_content . | |
bool | send_response (status code, const error &err) |
Sends a response that only consists of a header with a status code such as status::no_content . | |
virtual void | switch_protocol (std::unique_ptr< octet_stream::upper_layer > next)=0 |
Asks the stream to swap the HTTP layer with next after returning from consume . | |
![]() | |
virtual multiplexer & | mpx () noexcept=0 |
Returns the multiplexer instance that executes this protocol stack. | |
virtual bool | can_send_more () const noexcept=0 |
Queries whether the output device can accept more data straight away. | |
virtual bool | is_reading () const noexcept=0 |
Queries whether the lower layer is currently reading from its input device. | |
virtual void | write_later ()=0 |
Triggers a write callback after the write device signals downstream capacity. | |
virtual void | shutdown ()=0 |
Shuts down any connection or session gracefully. | |
virtual void | shutdown (const error &reason) |
Shuts down any connection or session du to an error. | |
Static Public Member Functions | |
static std::unique_ptr< server > | make (upper_layer_ptr up) |
Static Public Attributes | |
static constexpr uint32_t | default_max_request_size = 65'536 |
Default maximum size for incoming HTTP requests: 64KiB. | |
Implements the server part for the HTTP Protocol as defined in RFC 7231.
|
overridevirtual |
Called by the lower layer for cleaning up any state in case of an error or when disposed.
Implements caf::net::generic_upper_layer.
|
overridevirtual |
Adds a header field.
Users may only call this function between begin_header
and end_header
.
Implements caf::net::http::lower_layer.
|
overridevirtual |
Starts writing an HTTP header.
Implements caf::net::http::lower_layer.
|
overridevirtualnoexcept |
Queries whether the output device can accept more data straight away.
Implements caf::net::generic_lower_layer.
Consumes bytes from the lower layer.
buffer | Available bytes to read. |
delta | Bytes that arrived since last calling this function. |
Implements caf::net::octet_stream::upper_layer.
|
overridevirtual |
Queries whether all pending data has been sent.
The lower calls this function to decide whether it has to wait for write events on the socket.
Implements caf::net::generic_upper_layer.
|
overridevirtual |
Seals the header and transports it to the client.
Implements caf::net::http::lower_layer.
|
overridevirtualnoexcept |
Queries whether the lower layer is currently reading from its input device.
Implements caf::net::generic_lower_layer.
|
overridevirtualnoexcept |
Returns the multiplexer instance that executes this protocol stack.
Implements caf::net::generic_lower_layer.
|
overridevirtual |
Gives the upper layer an opportunity to add additional data to the output buffer.
Implements caf::net::generic_upper_layer.
|
overridevirtual |
Start or re-start reading data from the client.
Implements caf::net::http::lower_layer.
|
overridevirtual |
Sends a chunk of data if the full payload is unknown when starting to send.
Implements caf::net::http::lower_layer.
|
overridevirtual |
Sends the last chunk, completing a chunked payload.
Implements caf::net::http::lower_layer.
|
overridevirtual |
Sends the payload after the header.
Implements caf::net::http::lower_layer.
|
overridevirtual |
Shuts down any connection or session gracefully.
Any pending data gets flushed before closing the socket.
Implements caf::net::generic_lower_layer.
|
overridevirtual |
Initializes the upper layer.
down | A pointer to the lower layer that remains valid for the lifetime of the upper layer. |
Implements caf::net::octet_stream::upper_layer.
|
overridevirtual |
Stops reading messages until calling request_messages
.
Implements caf::net::http::lower_layer.
|
overridevirtual |
Asks the stream to swap the HTTP layer with next
after returning from consume
.
consume
. Implements caf::net::http::lower_layer.
|
overridevirtual |
Triggers a write callback after the write device signals downstream capacity.
Does nothing if this layer is already writing.
Implements caf::net::generic_lower_layer.