C++ Actor Framework 0.19
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
caf::net::http::server Class Reference

Implements the server part for the HTTP Protocol as defined in RFC 7231. More...

#include <server.hpp>

Inheritance diagram for caf::net::http::server:
caf::net::octet_stream::upper_layer caf::net::http::lower_layer caf::net::generic_upper_layer caf::net::generic_lower_layer

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
 
multiplexermpx () 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.
 
- Public Member Functions inherited from caf::net::http::lower_layer
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.
 
- Public Member Functions inherited from caf::net::generic_lower_layer
virtual multiplexermpx () 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 due to an error.
 

Static Public Member Functions

static std::unique_ptr< servermake (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.
 

Detailed Description

Implements the server part for the HTTP Protocol as defined in RFC 7231.

Member Function Documentation

◆ abort()

void caf::net::http::server::abort ( const error reason)
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.

◆ add_header_field()

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

Adds a header field.

Users may only call this function between begin_header and end_header.

Implements caf::net::http::lower_layer.

◆ begin_header()

void caf::net::http::server::begin_header ( status  code)
overridevirtual

Starts writing an HTTP header.

Implements caf::net::http::lower_layer.

◆ can_send_more()

bool caf::net::http::server::can_send_more ( ) const
overridevirtualnoexcept

Queries whether the output device can accept more data straight away.

Implements caf::net::generic_lower_layer.

◆ consume()

ptrdiff_t caf::net::http::server::consume ( byte_span  buffer,
byte_span  delta 
)
overridevirtual

Consumes bytes from the lower layer.

Parameters
bufferAvailable bytes to read.
deltaBytes that arrived since last calling this function.
Returns
The number of consumed bytes. May be zero if waiting for more input or negative to signal an error.

Implements caf::net::octet_stream::upper_layer.

◆ done_sending()

bool caf::net::http::server::done_sending ( )
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.

◆ end_header()

bool caf::net::http::server::end_header ( )
overridevirtual

Seals the header and transports it to the client.

Implements caf::net::http::lower_layer.

◆ is_reading()

bool caf::net::http::server::is_reading ( ) const
overridevirtualnoexcept

Queries whether the lower layer is currently reading from its input device.

Implements caf::net::generic_lower_layer.

◆ mpx()

multiplexer & caf::net::http::server::mpx ( )
overridevirtualnoexcept

Returns the multiplexer instance that executes this protocol stack.

Implements caf::net::generic_lower_layer.

◆ prepare_send()

void caf::net::http::server::prepare_send ( )
overridevirtual

Gives the upper layer an opportunity to add additional data to the output buffer.

Implements caf::net::generic_upper_layer.

◆ request_messages()

void caf::net::http::server::request_messages ( )
overridevirtual

Start or re-start reading data from the client.

Implements caf::net::http::lower_layer.

◆ send_chunk()

bool caf::net::http::server::send_chunk ( const_byte_span  bytes)
overridevirtual

Sends a chunk of data if the full payload is unknown when starting to send.

Implements caf::net::http::lower_layer.

◆ send_end_of_chunks()

bool caf::net::http::server::send_end_of_chunks ( )
overridevirtual

Sends the last chunk, completing a chunked payload.

Implements caf::net::http::lower_layer.

◆ send_payload()

bool caf::net::http::server::send_payload ( const_byte_span  bytes)
overridevirtual

Sends the payload after the header.

Implements caf::net::http::lower_layer.

◆ shutdown()

void caf::net::http::server::shutdown ( )
overridevirtual

Shuts down any connection or session gracefully.

Any pending data gets flushed before closing the socket.

Implements caf::net::generic_lower_layer.

◆ start()

error caf::net::http::server::start ( octet_stream::lower_layer down)
overridevirtual

Initializes the upper layer.

Parameters
downA pointer to the lower layer that remains valid for the lifetime of the upper layer.

Implements caf::net::octet_stream::upper_layer.

◆ suspend_reading()

void caf::net::http::server::suspend_reading ( )
overridevirtual

Stops reading messages until calling request_messages.

Implements caf::net::http::lower_layer.

◆ switch_protocol()

void caf::net::http::server::switch_protocol ( std::unique_ptr< octet_stream::upper_layer next)
overridevirtual

Asks the stream to swap the HTTP layer with next after returning from consume.

Note
may only be called from the upper layer in consume.

Implements caf::net::http::lower_layer.

◆ write_later()

void caf::net::http::server::write_later ( )
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.


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