Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::HttpOutgoingMessage Struct Reference

Outgoing message from the perspective of the participants of an HTTP transaction. More...

#include <HttpConnection.h>

Inheritance diagram for SC::HttpOutgoingMessage:
SC::HttpAsyncClientRequest SC::HttpResponse

Public Member Functions

Result addHeader (StringSpan headerName, StringSpan headerValue)
 Writes an http header to this response.
 
Result sendHeaders (Function< void(AsyncBufferView::ID)> callback={})
 Start sending response headers, before sending any data.
 
void reset ()
 Resets this object for it to be re-usable.
 
Result end ()
 Finalizes the writable stream after sending all in progress writes.
 
AsyncWritableStreamgetWritableStream ()
 Obtain writable stream for sending content back to connected client.
 
void setKeepAlive (bool keepAlive)
 Sets whether to keep the connection alive after this response.
 
bool getKeepAlive () const
 Gets whether the connection should be kept alive after this response.
 

Protected Types

enum class  KnownHeader : uint8_t {
  Connection ,
  Host ,
  UserAgent ,
  ContentLength ,
  ContentType ,
  TransferEncoding
}
 

Protected Member Functions

void setHeaderMemory (Span< char > memory)
 
void setWritableStream (AsyncWritableStream &stream)
 
bool hasHeader (KnownHeader header) const
 
bool hasSentHeaders () const
 
bool hasEnded () const
 

Protected Attributes

HttpFixedBufferWriter responseHeaders
 
Span< char > headerMemory
 
bool headersSent = false
 
bool endCalled = false
 
bool forceDisableKeepAlive = false
 Whether keep alive has been force disabled permanently.
 
bool keepAlive = true
 Whether to keep connection alive (HTTP/1.1 default)
 
bool connectionHeaderAdded = false
 Whether Connection header was manually added.
 
bool hostHeaderAdded = false
 
bool userAgentHeaderAdded = false
 
bool contentLengthAdded = false
 
bool contentTypeAdded = false
 
bool transferEncodingAdded = false
 
AsyncWritableStreamwritableStream = nullptr
 

Detailed Description

Outgoing message from the perspective of the participants of an HTTP transaction.

Member Function Documentation

◆ addHeader()

Result SC::HttpOutgoingMessage::addHeader ( StringSpan headerName,
StringSpan headerValue )

Writes an http header to this response.

Returns
Valid Result if header was added successfully.
Warning
Adding a "Connection" header can fail if keep-alive has been force disabled

◆ end()

Result SC::HttpOutgoingMessage::end ( )

Finalizes the writable stream after sending all in progress writes.

◆ getKeepAlive()

bool SC::HttpOutgoingMessage::getKeepAlive ( ) const
inlinenodiscard

Gets whether the connection should be kept alive after this response.

Returns
true if connection should be kept alive

◆ getWritableStream()

AsyncWritableStream & SC::HttpOutgoingMessage::getWritableStream ( )
inline

Obtain writable stream for sending content back to connected client.

◆ reset()

void SC::HttpOutgoingMessage::reset ( )

Resets this object for it to be re-usable.

◆ sendHeaders()

Result SC::HttpOutgoingMessage::sendHeaders ( Function< void(AsyncBufferView::ID)> callback = {})

Start sending response headers, before sending any data.

◆ setKeepAlive()

void SC::HttpOutgoingMessage::setKeepAlive ( bool keepAlive)

Sets whether to keep the connection alive after this response.

Parameters
keepAlivetrue to keep connection open for more requests, false to close after response
Warning
HttpConnection can force disable keep-alive when running out of connections to prevent server deadlock

Member Data Documentation

◆ connectionHeaderAdded

bool SC::HttpOutgoingMessage::connectionHeaderAdded = false
protected

Whether Connection header was manually added.

◆ forceDisableKeepAlive

bool SC::HttpOutgoingMessage::forceDisableKeepAlive = false
protected

Whether keep alive has been force disabled permanently.

◆ keepAlive

bool SC::HttpOutgoingMessage::keepAlive = true
protected

Whether to keep connection alive (HTTP/1.1 default)


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