Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
HttpResponse Class Reference

Public Member Functions

bool sendString (const String &text)
 
bool hasHeader (const String &name) SMING_DEPRECATED
 
void redirect (const String &location) SMING_DEPRECATED
 
void forbidden () SMING_DEPRECATED
 
void notFound () SMING_DEPRECATED
 
HttpResponsesetContentType (const String &type)
 
HttpResponsesetContentType (enum MimeType type)
 
HttpResponsesetCookie (const String &name, const String &value)
 
HttpResponsesetHeader (const String &name, const String &value)
 
HttpResponsesetCache (int maxAgeSeconds=3600, bool isPublic=false)
 
HttpResponsesetAllowCrossDomainOrigin (const String &controlAllowOrigin)
 
bool sendFile (String fileName, bool allowGzipFileCheck=true)
 Send file by name. More...
 
bool sendTemplate (TemplateStream *newTemplateInstance)
 Parse and send template file. More...
 
bool sendJsonObject (JsonObjectStream *newJsonStreamInstance) SMING_DEPRECATED
 Build and send JSON string. 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 ()
 Get response body as 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...
 

Public Attributes

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

Member Function Documentation

void HttpResponse::forbidden ( )
inline
Deprecated:
Use response.code = HTTP_STATUS_FORBIDDEN instead
void HttpResponse::freeStreams ( )

release allocated stream memory

String HttpResponse::getBody ( )

Get response body as a string.

Return values
String
Note
Use with caution if response is large
bool HttpResponse::hasHeader ( const String name)
inline
Deprecated:
Use headers.contains() instead
void HttpResponse::notFound ( )
inline
Deprecated:
Use response.code = HTTP_STATUS_NOT_FOUND instead
void HttpResponse::redirect ( const String location)
inline
Deprecated:
Use headers[HTTP_HEADER_LOCATION] instead
void HttpResponse::reset ( )

reset response so it can be re-used

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

Send data from the given stream object.

Parameters
newDataStream
type
Return values
falseon error
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
bool HttpResponse::sendFile ( String  fileName,
bool  allowGzipFileCheck = true 
)

Send file by name.

Parameters
fileName
allowGzipFileCheckIf true, check file extension to see if content commpressed
Return values
bool
bool HttpResponse::sendJsonObject ( JsonObjectStream newJsonStreamInstance)

Build and send JSON string.

Deprecated:
Use response.sendDataStream(stream, MIME_JSON) instead
bool HttpResponse::sendTemplate ( TemplateStream newTemplateInstance)

Parse and send template file.

Parameters
newTemplateInstance
Return values
bool
void HttpResponse::setBuffer ( ReadWriteStream buffer)

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

Parameters
buffer

Member Data Documentation

ReadWriteStream* HttpResponse::buffer = nullptr

Internal stream for storing strings and receiving responses.

unsigned HttpResponse::code = HTTP_STATUS_OK

The HTTP status response code.

IDataSourceStream* HttpResponse::stream = nullptr

The body stream.