Encapsulates an incoming or outgoing request. More...
#include <HttpRequest.h>
Public Types | |
| using | SslInitDelegate = Delegate< void(Ssl::Session &session, HttpRequest &request)> |
| Callback delegate type used to initialise an SSL session for a given request. More... | |
Public Member Functions | |
| HttpRequest () | |
| HttpRequest (const Url &uri) | |
| HttpRequest (const HttpRequest &value) | |
| Copy constructor. More... | |
| HttpRequest * | clone () const |
| Clone this request into a new object using the copy constructor. More... | |
| ~HttpRequest () | |
| HttpRequest * | setURL (const Url &uri) |
| HttpRequest * | setMethod (HttpMethod method) |
| HttpRequest * | setHeaders (const HttpHeaders &headers) |
| HttpRequest * | setHeader (const String &name, const String &value) |
| HttpRequest * | setPostParameter (const String &name, const String &value) |
| HttpRequest * | setFile (const String &formElementName, ReadWriteStream *stream) |
| Sets a file to be sent. More... | |
| HttpRequest * | setAuth (AuthAdapter *adapter) |
| const String & | getHeader (const String &name) |
| Get header field value. More... | |
| const String & | getPostParameter (const String &name) |
| Get POST parameter value. More... | |
| String | getQueryParameter (const String &name, const String &defaultValue=nullptr) const |
| Get parameter from query fields. More... | |
| String | getBody () |
| Moves content from the body stream into a String. More... | |
| IDataSourceStream * | getBodyStream () |
| Return the current body stream. More... | |
| HttpRequest * | setResponseStream (ReadWriteStream *stream) |
| Instead of storing the response body we can set a stream that will take care to process it. More... | |
| ReadWriteStream * | getResponseStream () |
| Get the response stream (if any) More... | |
| HttpRequest * | onHeadersComplete (RequestHeadersCompletedDelegate delegateFunction) |
| HttpRequest * | onBody (RequestBodyDelegate delegateFunction) |
| HttpRequest * | onRequestComplete (RequestCompletedDelegate delegateFunction) |
| void | reset () |
| Clear buffers and reset to default state in preparation for another request. More... | |
| HttpRequest * | onSslInit (SslInitDelegate delegate) |
| To customise SSL session options, provide a callback. More... | |
| String | toString () const |
| Tries to present a readable version of the current request values. More... | |
Set request body content | |
| HttpRequest * | setBody (const String &body) |
| Set body from String object. More... | |
| HttpRequest * | setBody (String &&body) noexcept |
| Set body from String object using move semantics: body will be invalid on return. More... | |
| HttpRequest * | setBody (IDataSourceStream *stream) |
| Set body using given stream object, and retain ownership. More... | |
| HttpRequest * | setBody (const uint8_t *rawData, size_t length) |
| Set body content by copying binary data. More... | |
Static Public Member Functions | |
| static String | toString (const HttpRequest &req) |
| Tries to present a readable version of the request. More... | |
Public Attributes | |
| Url | uri |
| Request URL. More... | |
| HttpMethod | method = HTTP_GET |
| Request method. More... | |
| HttpHeaders | headers |
| Request headers. More... | |
| HttpParams | postParams |
| POST parameters. More... | |
| HttpFiles | files |
| Attached files. More... | |
| int | retries = 0 |
| how many times the request should be send again... More... | |
| void * | args = nullptr |
| Used to store data that should be valid during a single request. More... | |
Protected Attributes | |
| RequestHeadersCompletedDelegate | headersCompletedDelegate |
| RequestBodyDelegate | requestBodyDelegate |
| RequestCompletedDelegate | requestCompletedDelegate |
| SslInitDelegate | sslInitDelegate |
| IDataSourceStream * | bodyStream = nullptr |
| ReadWriteStream * | responseStream = nullptr |
| User-requested stream to store response. More... | |
| AuthAdapter * | auth = nullptr |
Friends | |
| class | HttpClientConnection |
| class | HttpServerConnection |
Detailed Description
Encapsulates an incoming or outgoing request.
Member Typedef Documentation
◆ SslInitDelegate
| using HttpRequest::SslInitDelegate = Delegate<void(Ssl::Session& session, HttpRequest& request)> |
Callback delegate type used to initialise an SSL session for a given request.
Constructor & Destructor Documentation
◆ HttpRequest() [1/3]
|
inline |
◆ HttpRequest() [2/3]
|
inline |
◆ HttpRequest() [3/3]
|
inline |
Copy constructor.
- Note
- Internal streams are not copied so these must be dealt with afterwards
◆ ~HttpRequest()
|
inline |
Member Function Documentation
◆ clone()
|
inline |
Clone this request into a new object using the copy constructor.
- Return values
-
HttpRequest* The new request object
◆ 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.
◆ getBodyStream()
|
inline |
Return the current body stream.
- Return values
-
IDataSourceStream*
- Note
- may return null
◆ getHeader()
Get header field value.
- Parameters
-
name Name of field
- Return values
-
const String& Value, will be invalid (i.e. if() == false) if field not present
◆ getPostParameter()
Get POST parameter value.
- Parameters
-
name Name of parameter
- Return values
-
const String& Value, will be invalid (i.e. if() == false) if field not present
◆ getQueryParameter()
|
inline |
Get parameter from query fields.
- Parameters
-
name Name of parameter defaultValue Optional default value to use if requested parameter not present
◆ getResponseStream()
|
inline |
Get the response stream (if any)
◆ onBody()
|
inline |
◆ onHeadersComplete()
|
inline |
◆ onRequestComplete()
|
inline |
◆ onSslInit()
|
inline |
To customise SSL session options, provide a callback.
- Parameters
-
delegate Invoked before creating SSL connection
◆ reset()
| void HttpRequest::reset | ( | ) |
Clear buffers and reset to default state in preparation for another request.
◆ setAuth()
|
inline |
◆ setBody() [1/4]
|
inline |
Set body from String object.
◆ setBody() [2/4]
| HttpRequest* HttpRequest::setBody | ( | const uint8_t * | rawData, |
| size_t | length | ||
| ) |
Set body content by copying binary data.
- Parameters
-
rawData Data to copy length Number of bytes to copy
◆ setBody() [3/4]
| HttpRequest* HttpRequest::setBody | ( | IDataSourceStream * | stream | ) |
Set body using given stream object, and retain ownership.
◆ setBody() [4/4]
|
noexcept |
Set body from String object using move semantics: body will be invalid on return.
◆ setFile()
|
inline |
Sets a file to be sent.
- Parameters
-
formElementName The name of the element in the form stream Pointer to the stream (doesn't have to be a FileStream)
- Return values
-
HttpRequest*
◆ setHeader()
|
inline |
◆ setHeaders()
|
inline |
◆ setMethod()
|
inline |
◆ setPostParameter()
|
inline |
◆ setResponseStream()
| 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.
◆ setURL()
|
inline |
◆ toString() [1/2]
| String HttpRequest::toString | ( | ) | const |
Tries to present a readable version of the current request values.
- Return values
-
String
◆ toString() [2/2]
|
inlinestatic |
Friends And Related Function Documentation
◆ HttpClientConnection
|
friend |
◆ HttpServerConnection
|
friend |
Member Data Documentation
◆ args
| void* HttpRequest::args = nullptr |
Used to store data that should be valid during a single request.
◆ auth
|
protected |
◆ bodyStream
|
protected |
◆ files
| HttpFiles HttpRequest::files |
Attached files.
◆ headers
| HttpHeaders HttpRequest::headers |
Request headers.
◆ headersCompletedDelegate
|
protected |
◆ method
| HttpMethod HttpRequest::method = HTTP_GET |
Request method.
◆ postParams
| HttpParams HttpRequest::postParams |
POST parameters.
◆ requestBodyDelegate
|
protected |
◆ requestCompletedDelegate
|
protected |
◆ responseStream
|
protected |
User-requested stream to store response.
◆ retries
| int HttpRequest::retries = 0 |
how many times the request should be send again...
◆ sslInitDelegate
|
protected |
◆ uri
| Url HttpRequest::uri |
Request URL.
The documentation for this class was generated from the following file:
1.8.17