staticlib_pion  2.0.2
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Public Member Functions | Static Public Member Functions | List of all members
staticlib::pion::http_response_writer Class Reference

Sends HTTP data asynchronously. More...

#include <staticlib/pion/http_response_writer.hpp>

Public Member Functions

 http_response_writer (tcp_connection_ptr &tcp_conn, const http_request &http_request)
 Constructor to be used with std::make_unique
 http_response_writer (const http_response_writer &)
 Deleted copy constructor.
http_response_writer & operator= (const http_response_writer &)
 Deleted copy assignment operator.
http_response & get_response ()
 Returns a non-const reference to the response that will be sent.
void clear ()
 Clears out all of the memory buffers used to cache payload content data.
void write (sl::io::span< const char > data)
 Write payload content.
void write_nocopy (sl::io::span< const char > data)
 Write payload content; the data written is not copied, and therefore must persist until the message has finished sending.
template<typename SendHandler >
void send_chunk (SendHandler send_handler)
 Sends all data buffered as a single HTTP chunk.
tcp_connection_ptr & get_connection ()
 Returns a shared pointer to the TCP connection.
size_t get_content_length () const
 Returns the length of the payload content (in bytes)
void supports_chunked_messages (bool b)
 Sets whether or not the client supports chunked messages.
bool supports_chunked_messages () const
 Returns true if the client supports chunked messages.
bool sending_chunked_message () const
 Returns true if we are sending a chunked message to the client.

Static Public Member Functions

static void send (std::unique_ptr< http_response_writer > self)
 Sends all data buffered as a single HTTP message (without chunking).
static void send_final_chunk (std::unique_ptr< http_response_writer > self)
 Sends all data buffered (if any) and also sends the final HTTP chunk.

Detailed Description

Sends HTTP data asynchronously.

Constructor & Destructor Documentation

staticlib::pion::http_response_writer::http_response_writer ( tcp_connection_ptr &  tcp_conn,
const http_request &  http_request 
)
inline

Constructor to be used with std::make_unique

Parameters
tcp_connTCP connection used to send the response
http_requestthe request we are responding to
staticlib::pion::http_response_writer::http_response_writer ( const http_response_writer &  )

Deleted copy constructor.

Member Function Documentation

void staticlib::pion::http_response_writer::clear ( )
inline

Clears out all of the memory buffers used to cache payload content data.

tcp_connection_ptr& staticlib::pion::http_response_writer::get_connection ( )
inline

Returns a shared pointer to the TCP connection.

Returns
shared pointer to the TCP connection
size_t staticlib::pion::http_response_writer::get_content_length ( ) const
inline

Returns the length of the payload content (in bytes)

Returns
length of the payload content (in bytes)
http_response& staticlib::pion::http_response_writer::get_response ( )
inline

Returns a non-const reference to the response that will be sent.

Returns
reference to the response that will be sent
http_response_writer& staticlib::pion::http_response_writer::operator= ( const http_response_writer &  )

Deleted copy assignment operator.

static void staticlib::pion::http_response_writer::send ( std::unique_ptr< http_response_writer >  self)
inlinestatic

Sends all data buffered as a single HTTP message (without chunking).

Following a call to this function, it is not thread safe to use your reference to the writer object.

Parameters
self-owninginstance
template<typename SendHandler >
void staticlib::pion::http_response_writer::send_chunk ( SendHandler  send_handler)
inline

Sends all data buffered as a single HTTP chunk.

Following a call to this function, it is not thread safe to use your reference to the writer object until the send_handler has been called.

Parameters
send_handlerfunction that is called after the chunk has been sent to the client. Your callback function must end by calling one of send_chunk() or send_final_chunk(). Also, be sure to clear() the writer before writing data to it.
static void staticlib::pion::http_response_writer::send_final_chunk ( std::unique_ptr< http_response_writer >  self)
inlinestatic

Sends all data buffered (if any) and also sends the final HTTP chunk.

This function (either overloaded version) must be called following any calls to send_chunk(). Following a call to this function, it is not thread safe to use your reference to the writer object.

Parameters
self-owninginstance
bool staticlib::pion::http_response_writer::sending_chunked_message ( ) const
inline

Returns true if we are sending a chunked message to the client.

Returns
true if we are sending a chunked message to the client
void staticlib::pion::http_response_writer::supports_chunked_messages ( bool  b)
inline

Sets whether or not the client supports chunked messages.

Parameters
bwhether or not the client supports chunked messages
bool staticlib::pion::http_response_writer::supports_chunked_messages ( ) const
inline

Returns true if the client supports chunked messages.

Returns
true if the client supports chunked messages
void staticlib::pion::http_response_writer::write ( sl::io::span< const char >  data)
inline

Write payload content.

Parameters
datato append to the payload content
void staticlib::pion::http_response_writer::write_nocopy ( sl::io::span< const char >  data)
inline

Write payload content; the data written is not copied, and therefore must persist until the message has finished sending.

Parameters
datathe data to append to the payload content

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