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

Public Member Functions

 HttpRequest (const Url &uri)
 
 HttpRequest (const HttpRequest &value)
 Copy constructor. More...
 
HttpRequestclone () const
 Clone this request into a new object using the copy constructor. More...
 
HttpRequestoperator= (const HttpRequest &rhs) SMING_DEPRECATED
 
HttpRequestsetURL (const Url &uri)
 
HttpRequestsetMethod (HttpMethod method)
 
HttpRequestsetHeaders (const HttpHeaders &headers)
 
HttpRequestsetHeader (const String &name, const String &value)
 
HttpRequestsetPostParameters (const HttpParams &params) SMING_DEPRECATED
 
HttpRequestsetPostParameter (const String &name, const String &value)
 
HttpRequestsetFile (const String &formElementName, IDataSourceStream *stream)
 Sets a file to be sent. More...
 
HttpRequestsetAuth (AuthAdapter *adapter)
 
const StringgetHeader (const String &name)
 
const StringgetPostParameter (const String &name)
 
String getPath () SMING_DEPRECATED
 
String getQueryParameter (const String &parameterName, const String &defaultValue=nullptr) const
 
String getBody ()
 Returns content from the body stream as string. More...
 
IDataSourceStreamgetBodyStream ()
 Return the current body stream and pass ownership to the caller. More...
 
HttpRequestsetBody (const String &body)
 
HttpRequestsetBody (IDataSourceStream *stream)
 
HttpRequestsetBody (const uint8_t *rawData, size_t length)
 
HttpRequestsetResponseStream (ReadWriteStream *stream)
 Instead of storing the response body we can set a stream that will take care to process it. More...
 
ReadWriteStreamgetResponseStream ()
 Get the response stream (if any) More...
 
HttpRequestonHeadersComplete (RequestHeadersCompletedDelegate delegateFunction)
 
HttpRequestonBody (RequestBodyDelegate delegateFunction)
 
HttpRequestonRequestComplete (RequestCompletedDelegate delegateFunction)
 
void reset ()
 Clear buffers and reset to default state in preparation for another request. More...
 
HttpRequestsetSslOptions (uint32_t sslOptions)
 
uint32_t getSslOptions ()
 
HttpRequestpinCertificate (SslFingerprints &fingerprints)
 Requires(pins) the remote SSL certificate to match certain fingerprints Check if SHA256 hash of Subject Public Key Info matches the one given. More...
 
HttpRequestsetSslKeyCert (const SslKeyCertPair &keyCertPair)
 Sets client private key, certificate and password from memory. More...
 
String toString ()
 Tries to present a readable version of the current request values. More...
 

Public Attributes

Url uri
 
HttpMethod method = HTTP_GET
 
HttpHeaders headers
 
HttpParams postParams
 
int retries = 0
 
void * args = nullptr
 

Protected Attributes

RequestHeadersCompletedDelegate headersCompletedDelegate
 
RequestBodyDelegate requestBodyDelegate
 
RequestCompletedDelegate requestCompletedDelegate
 
IDataSourceStreambodyStream = nullptr
 
ReadWriteStreamresponseStream = nullptr
 User-requested stream to store response. More...
 
AuthAdapterauth = nullptr
 
uint32_t sslOptions = 0
 
SslFingerprints sslFingerprints
 
SslKeyCertPair sslKeyCertPair
 

Friends

class HttpClientConnection
 
class HttpServerConnection
 

Constructor & Destructor Documentation

HttpRequest::HttpRequest ( const HttpRequest value)

Copy constructor.

Note
Internal streams are not copied so these must be dealt with afterwards

Member Function Documentation

HttpRequest* HttpRequest::clone ( ) const
inline

Clone this request into a new object using the copy constructor.

Return values
HttpRequest*The new request object
See also
HttpRequest(const HttpRequest& value)
String HttpRequest::getBody ( )

Returns content from the body stream as string.

Return values
String
Note
This method consumes the stream and it will work only with text data. If you have binary data in the stream use getBodyStream instead.
Allocation of String doubles amount of memory required, so use with care.
IDataSourceStream* HttpRequest::getBodyStream ( )

Return the current body stream and pass ownership to the caller.

Return values
IDataSourceStream*
Note
may return null
String HttpRequest::getPath ( )
inline
Deprecated:
Use uri.Path instead
ReadWriteStream* HttpRequest::getResponseStream ( )
inline

Get the response stream (if any)

HttpRequest& HttpRequest::operator= ( const HttpRequest rhs)
inline
Deprecated:
Please use clone() instead
HttpRequest* HttpRequest::pinCertificate ( SslFingerprints fingerprints)
inline

Requires(pins) the remote SSL certificate to match certain fingerprints Check if SHA256 hash of Subject Public Key Info matches the one given.

Parameters
fingerprints- passes the certificate fingerprints by reference.
Return values
booltrue of success, false or failure
void HttpRequest::reset ( )

Clear buffers and reset to default state in preparation for another request.

HttpRequest* HttpRequest::setFile ( const String formElementName,
IDataSourceStream stream 
)
inline

Sets a file to be sent.

Parameters
constString& formElementName the name of the element in the form
IDataSourceStream*stream - pointer to the stream (doesn't have to be a FileStream)
Return values
HttpRequest*
HttpRequest* HttpRequest::setPostParameters ( const HttpParams params)
inline
Deprecated:
Set postParams directly, i.e. request.postParams = params
HttpRequest* HttpRequest::setResponseStream ( ReadWriteStream stream)

Instead of storing the response body we can set a stream that will take care to process it.

Parameters
stream
Return values
HttpRequest*
Note
The response to this request will be stored in the user-provided stream.
HttpRequest* HttpRequest::setSslKeyCert ( const SslKeyCertPair keyCertPair)
inline

Sets client private key, certificate and password from memory.

Parameters
SSLKeyCertPair
boolfreeAfterHandshake
Return values
HttpRequestpointer
String HttpRequest::toString ( )

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

Return values
String

Member Data Documentation

ReadWriteStream* HttpRequest::responseStream = nullptr
protected

User-requested stream to store response.