HTTP request. More...
#include "SuperpoweredHTTP.h"
Public Member Functions | |
httpRequest (char *url) | |
Constructor with url. More... | |
httpRequest (const char *url) | |
Constructor with url. More... | |
httpRequest (int urlMaxSizeBytes, const char *format,...) | |
Constructor with printing a url similar to sprintf(). More... | |
~httpRequest () | |
Destructor. More... | |
httpData * | addData (char *key, httpDataMode keyMode, char *value, httpDataMode valueMode) |
Adds a key/value data pair to the request. More... | |
void | addFileToPost (const char *path, const char *filename=0) |
Adds a file to send with the body of the request (upload for example). More... | |
httpData * | addFullHeader (const char *header) |
Adds a header to the request as a string. More... | |
httpData * | addHeader (char *key, httpDataMode keyMode, char *value, httpDataMode valueMode) |
Adds a header to the request as a key/value pair. More... | |
httpRequest * | copy (const char *anotherURL=0) |
Creates a new request instance from the current request. More... | |
void | sendAsync (httpRequestCallback callback=0, void *clientData=0, const char *tempFolderPath=0, bool flushAfterWrite=false, httpLogCallback log=0) |
Sends the HTTP request asynchronously with opening a background thread for the transfer. More... | |
httpResponse * | sendBlocking (httpRequestCallback callback=0, void *clientData=0, const char *tempFolderPath=0, bool flushAfterWrite=false, httpLogCallback log=0) |
Sends the HTTP request and blocks until the transfer finishes. More... | |
void | setCustomContent (const char *contentTypeHeaderValue, const char *content, unsigned int contentLengthBytes) |
Adds a custom body to the request. More... | |
void | setURL (char *url) |
Sets the url (and discards the old one). More... | |
void | setURL (const char *url) |
Sets the url (and discards the old one). More... | |
void | setURL (unsigned int urlMaxSizeBytes, const char *format,...) |
Sets the url (and discards the old one). More... | |
Public Attributes | |
char * | customContent |
Custom body for the query. Can not be used with fileToPostPath. More... | |
unsigned int | customContentLengthBytes |
The size in bytes of customContent. More... | |
char * | customContentTypeHeaderValue |
Content type of the custom content. Example: "text/css". More... | |
bool | customDownloadHandling |
Set to true to use your own data handling/file writing. Default: false. More... | |
httpData * | data |
A linked list of data in key/value pairs to be sent with the request. NULL by default. For GET and DELETE requests the data will be passed in the query string. Encoding (such as url encoding) will be handled automatically. Use addData to add data conveniently. More... | |
bool | disableHttpCacheControl |
Disable HTTP caching by adding a Cache-Control: no-cache, no-store, must-revalidate header. Default: true. More... | |
char * | fileToPostName |
Optional filename for fileToPostPath. If NULL, will use the file name in fileToPostPath. NULL by default. More... | |
char * | fileToPostPath |
Path to a file to send in the body of the query. Typically used with POST requests. NULL by default. More... | |
httpData * | headers |
A linked list of custom headers in key/value pairs to be sent with the request. NULL by default. Example: "Key" + "Value" will be sent as "Key: Value". Use addHeader to add a header conveniently. More... | |
unsigned int | maximumBytesToReceive |
Maximum bytes to receive (will interrupt the transfer if reached). Default: 1024 * 1024 * 100 (100 megabytes) More... | |
unsigned int | maximumNumberOfRedirects |
Maximum number of redirects. Default: 20. More... | |
const char * | method |
HTTP method. Default: "GET". More... | |
unsigned int | timeoutSeconds |
Timeout in seconds. Default: 60. More... | |
char * | url |
The url to connect to. Might include the query string, however the "data" parameter is more convenient to construct query strings. NULL by default. More... | |
HTTP request.
Superpowered::httpRequest::httpRequest | ( | char * | url | ) |
Constructor with url.
Example: request = new Superpowered::request(myURL);
url | The relative url. |
Superpowered::httpRequest::httpRequest | ( | const char * | url | ) |
Constructor with url.
Example: request = new Superpowered::request("https://superpowered.com");
url | The relative url. |
Superpowered::httpRequest::httpRequest | ( | int | urlMaxSizeBytes, |
const char * | format, | ||
... | |||
) |
Constructor with printing a url similar to sprintf().
Example: request = new Superpowered::request(64, "https://example.com/article/%i", 12345);
urlMaxSizeBytes | The maximum predicted memory usage of the result string. Can be any safe number. |
format | Contains a format string that follows the same specifications as format in printf(). |
... | Depending on the format string, the function may expect a sequence of additional arguments, similar to printf(). |
Superpowered::httpRequest::~httpRequest | ( | ) |
Destructor.
httpData* Superpowered::httpRequest::addData | ( | char * | key, |
httpDataMode | keyMode, | ||
char * | value, | ||
httpDataMode | valueMode | ||
) |
Adds a key/value data pair to the request.
For GET and DELETE requests it will passed in the query string. Encoding (such as url encoding) will be handled automatically.
key | The key. |
keyMode | Data mode for the key. |
value | The value. |
valueMode | Data mode for the value. |
void Superpowered::httpRequest::addFileToPost | ( | const char * | path, |
const char * | filename = 0 |
||
) |
Adds a file to send with the body of the request (upload for example).
path | File system path to the file. |
filename | Optional file name. If NULL, will use the file name in the file system path. |
httpData* Superpowered::httpRequest::addFullHeader | ( | const char * | header | ) |
Adds a header to the request as a string.
Example: request->addHeader("Authorization: Bearer 12345");
header | The header string. |
httpData* Superpowered::httpRequest::addHeader | ( | char * | key, |
httpDataMode | keyMode, | ||
char * | value, | ||
httpDataMode | valueMode | ||
) |
Adds a header to the request as a key/value pair.
Example: "Key" + "Value" will be sent as "Key: Value".
key | The key. |
keyMode | Data mode for the key. |
value | The value. |
valueMode | Data mode for the value. |
httpRequest* Superpowered::httpRequest::copy | ( | const char * | anotherURL = 0 | ) |
Creates a new request instance from the current request.
Example: anotherRequest = request->copy();
anotherURL | Optional. Will overwrite the url value. |
void Superpowered::httpRequest::sendAsync | ( | httpRequestCallback | callback = 0 , |
void * | clientData = 0 , |
||
const char * | tempFolderPath = 0 , |
||
bool | flushAfterWrite = false , |
||
httpLogCallback | log = 0 |
||
) |
Sends the HTTP request asynchronously with opening a background thread for the transfer.
callback | Receive progress and result with this callback. |
clientData | Your custom data with the callback. |
tempFolderPath | If not NULL, the server response body will be written to a temporary file (into this folder) instead of memory. |
flushAfterWrite | True to fflush() after every file write (useful for progressive downloads). |
log | Use this for debugging purposes to see the full HTTP log. |
httpResponse* Superpowered::httpRequest::sendBlocking | ( | httpRequestCallback | callback = 0 , |
void * | clientData = 0 , |
||
const char * | tempFolderPath = 0 , |
||
bool | flushAfterWrite = false , |
||
httpLogCallback | log = 0 |
||
) |
Sends the HTTP request and blocks until the transfer finishes.
callback | Receive progress or perform custom data handling with this callback. |
clientData | Your custom data with the callback. |
tempFolderPath | If not NULL, the server response body will be written to a temporary file (into this folder) instead of memory. |
flushAfterWrite | True to fflush() after every file write (useful for progressive downloads). |
log | Use this for debugging purposes to see the full HTTP log. |
void Superpowered::httpRequest::setCustomContent | ( | const char * | contentTypeHeaderValue, |
const char * | content, | ||
unsigned int | contentLengthBytes | ||
) |
Adds a custom body to the request.
The content will be copied using strdup.
contentTypeHeaderValue | Content type of the custom content. Example: "text/css". |
content | Custom body. |
contentLengthBytes | The size of the custom body in bytes (not including trailing zero, you can use strlen for example). |
void Superpowered::httpRequest::setURL | ( | char * | url | ) |
Sets the url (and discards the old one).
Example: request->setURL(myURL);
url | The relative url. |
void Superpowered::httpRequest::setURL | ( | const char * | url | ) |
Sets the url (and discards the old one).
Example: request->setURL("https://superpowered.com");
url | The relative url. |
void Superpowered::httpRequest::setURL | ( | unsigned int | urlMaxSizeBytes, |
const char * | format, | ||
... | |||
) |
Sets the url (and discards the old one).
Example: request->setURL(64, "https://example.com/article/%i", 12345);
urlMaxSizeBytes | The maximum predicted memory usage of the result string. Can be any safe number. |
format | Contains a format string that follows the same specifications as format in printf(). |
... | Depending on the format string, the function may expect a sequence of additional arguments, similar to printf(). |
char* Superpowered::httpRequest::customContent |
Custom body for the query. Can not be used with fileToPostPath.
unsigned int Superpowered::httpRequest::customContentLengthBytes |
The size in bytes of customContent.
char* Superpowered::httpRequest::customContentTypeHeaderValue |
Content type of the custom content. Example: "text/css".
bool Superpowered::httpRequest::customDownloadHandling |
Set to true to use your own data handling/file writing. Default: false.
httpData* Superpowered::httpRequest::data |
A linked list of data in key/value pairs to be sent with the request. NULL by default. For GET and DELETE requests the data will be passed in the query string. Encoding (such as url encoding) will be handled automatically. Use addData to add data conveniently.
bool Superpowered::httpRequest::disableHttpCacheControl |
Disable HTTP caching by adding a Cache-Control: no-cache, no-store, must-revalidate header. Default: true.
char* Superpowered::httpRequest::fileToPostName |
Optional filename for fileToPostPath. If NULL, will use the file name in fileToPostPath. NULL by default.
char* Superpowered::httpRequest::fileToPostPath |
Path to a file to send in the body of the query. Typically used with POST requests. NULL by default.
httpData* Superpowered::httpRequest::headers |
A linked list of custom headers in key/value pairs to be sent with the request. NULL by default. Example: "Key" + "Value" will be sent as "Key: Value". Use addHeader to add a header conveniently.
unsigned int Superpowered::httpRequest::maximumBytesToReceive |
Maximum bytes to receive (will interrupt the transfer if reached). Default: 1024 * 1024 * 100 (100 megabytes)
unsigned int Superpowered::httpRequest::maximumNumberOfRedirects |
Maximum number of redirects. Default: 20.
const char* Superpowered::httpRequest::method |
HTTP method. Default: "GET".
unsigned int Superpowered::httpRequest::timeoutSeconds |
Timeout in seconds. Default: 60.
char* Superpowered::httpRequest::url |
The url to connect to. Might include the query string, however the "data" parameter is more convenient to construct query strings. NULL by default.