Represents either an incoming or outgoing response to a HTTP request. More...

#include <HttpResponse.h>

Collaboration diagram for HttpResponse:

Public Member Functions

 ~HttpResponse ()
 
bool sendString (const String &text)
 
bool sendString (String &&text) noexcept
 
HttpResponsesetContentType (const String &type)
 
HttpResponsesetContentType (enum MimeType type)
 
HttpResponsesetCookie (const String &name, const String &value, bool append=false)
 
HttpResponsesetHeader (const String &name, const String &value)
 
HttpResponsesetCache (int maxAgeSeconds=3600, bool isPublic=false)
 
HttpResponsesetAllowCrossDomainOrigin (const String &controlAllowOrigin)
 
bool sendFile (const String &fileName, bool allowGzipFileCheck=true)
 Send file by name. More...
 
bool sendNamedStream (IDataSourceStream *newDataStream)
 Parse and send stream, using the name to determine the content type. More...
 
bool sendDataStream (IDataSourceStream *newDataStream, enum MimeType type)
 Send data from the given stream object. More...
 
bool sendDataStream (IDataSourceStream *newDataStream, const String &reqContentType=nullptr)
 Send data from the given stream object. More...
 
String getBody ()
 Moves content from the body stream into a String. More...
 
void reset ()
 reset response so it can be re-used More...
 
void setBuffer (ReadWriteStream *buffer)
 Called by connection to specify where incoming response data is written. More...
 
void freeStreams ()
 release allocated stream memory More...
 
bool isSuccess ()
 Determine if the response status indicates success. More...
 
String toString () const
 Tries to present a readable version of the current response values. More...
 

Public Attributes

HttpStatus code = HTTP_STATUS_OK
 The HTTP status response code. More...
 
HttpHeaders headers
 Response headers. More...
 
ReadWriteStreambuffer = nullptr
 Internal stream for storing strings and receiving responses. More...
 
IDataSourceStreamstream = nullptr
 The body stream. More...
 

Detailed Description

Represents either an incoming or outgoing response to a HTTP request.

Constructor & Destructor Documentation

◆ ~HttpResponse()

HttpResponse::~HttpResponse ( )
inline

Member Function Documentation

◆ freeStreams()

void HttpResponse::freeStreams ( )

release allocated stream memory

◆ getBody()

String HttpResponse::getBody ( )
inline

Moves content from the body stream into a String.

Return values
String
Note
Move semantics are used to ensure that no/minimal additional memory is required. If your application has set a non-memory stream type then the method will fail and return an invalid String. The stream content will be left unchanged.

◆ isSuccess()

bool HttpResponse::isSuccess ( )
inline

Determine if the response status indicates success.

◆ reset()

void HttpResponse::reset ( )

reset response so it can be re-used

◆ sendDataStream() [1/2]

bool HttpResponse::sendDataStream ( IDataSourceStream newDataStream,
const String reqContentType = nullptr 
)

Send data from the given stream object.

Parameters
newDataStream
reqContentType
Return values
onerror returns false and stream will have been destroyed so any external references to it must be invalidated.
Note
all data is submitted via stream so called by internal routines

◆ sendDataStream() [2/2]

bool HttpResponse::sendDataStream ( IDataSourceStream newDataStream,
enum MimeType  type 
)
inline

Send data from the given stream object.

Parameters
newDataStream
type
Return values
falseon error

◆ sendFile()

bool HttpResponse::sendFile ( const String fileName,
bool  allowGzipFileCheck = true 
)

Send file by name.

Parameters
fileName
allowGzipFileCheckIf true, check file extension to see if content compressed
Return values
bool

◆ sendNamedStream()

bool HttpResponse::sendNamedStream ( IDataSourceStream newDataStream)

Parse and send stream, using the name to determine the content type.

Parameters
newDataStreamIf not set already, the contentType will be obtained from the name of this stream
Return values
bool

◆ sendString() [1/2]

bool HttpResponse::sendString ( const String text)

◆ sendString() [2/2]

bool HttpResponse::sendString ( String &&  text)
noexcept

◆ setAllowCrossDomainOrigin()

HttpResponse* HttpResponse::setAllowCrossDomainOrigin ( const String controlAllowOrigin)
inline

◆ setBuffer()

void HttpResponse::setBuffer ( ReadWriteStream buffer)

Called by connection to specify where incoming response data is written.

Parameters
buffer

◆ setCache()

HttpResponse* HttpResponse::setCache ( int  maxAgeSeconds = 3600,
bool  isPublic = false 
)

◆ setContentType() [1/2]

HttpResponse* HttpResponse::setContentType ( const String type)
inline

◆ setContentType() [2/2]

HttpResponse* HttpResponse::setContentType ( enum MimeType  type)
inline

◆ setCookie()

HttpResponse* HttpResponse::setCookie ( const String name,
const String value,
bool  append = false 
)

◆ setHeader()

HttpResponse* HttpResponse::setHeader ( const String name,
const String value 
)
inline

◆ toString()

String HttpResponse::toString ( ) const

Tries to present a readable version of the current response values.

Return values
String

Member Data Documentation

◆ buffer

ReadWriteStream* HttpResponse::buffer = nullptr

Internal stream for storing strings and receiving responses.

◆ code

HttpStatus HttpResponse::code = HTTP_STATUS_OK

The HTTP status response code.

◆ headers

HttpHeaders HttpResponse::headers

Response headers.

◆ stream

IDataSourceStream* HttpResponse::stream = nullptr

The body stream.


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