SuperpoweredSDK  v2.0.2
Superpowered Audio SDK
Superpowered::httpRequest Class Reference

HTTP request. More...

#include "SuperpoweredHTTP.h"

Collaboration diagram for Superpowered::httpRequest:

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...
 
httpDataaddData (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...
 
httpDataaddFullHeader (const char *header)
 Adds a header to the request as a string. More...
 
httpDataaddHeader (char *key, httpDataMode keyMode, char *value, httpDataMode valueMode)
 Adds a header to the request as a key/value pair. More...
 
httpRequestcopy (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...
 
httpResponsesendBlocking (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...
 
httpDatadata
 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...
 
httpDataheaders
 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...
 

Detailed Description

HTTP request.

Constructor & Destructor Documentation

◆ httpRequest() [1/3]

Superpowered::httpRequest::httpRequest ( char *  url)

Constructor with url.

Example: request = new Superpowered::request(myURL);

Parameters
urlThe relative url.

◆ httpRequest() [2/3]

Superpowered::httpRequest::httpRequest ( const char *  url)

Constructor with url.

Example: request = new Superpowered::request("https://superpowered.com");

Parameters
urlThe relative url.

◆ httpRequest() [3/3]

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);

Parameters
urlMaxSizeBytesThe maximum predicted memory usage of the result string. Can be any safe number.
formatContains 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().

◆ ~httpRequest()

Superpowered::httpRequest::~httpRequest ( )

Destructor.

Member Function Documentation

◆ addData()

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.

Parameters
keyThe key.
keyModeData mode for the key.
valueThe value.
valueModeData mode for the value.
Returns
Pointer to the data.

◆ addFileToPost()

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).

Parameters
pathFile system path to the file.
filenameOptional file name. If NULL, will use the file name in the file system path.

◆ addFullHeader()

httpData* Superpowered::httpRequest::addFullHeader ( const char *  header)

Adds a header to the request as a string.

Example: request->addHeader("Authorization: Bearer 12345");

Parameters
headerThe header string.
Returns
Pointer to the header.

◆ addHeader()

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".

Parameters
keyThe key.
keyModeData mode for the key.
valueThe value.
valueModeData mode for the value.
Returns
Pointer to the header.

◆ copy()

httpRequest* Superpowered::httpRequest::copy ( const char *  anotherURL = 0)

Creates a new request instance from the current request.

Example: anotherRequest = request->copy();

Parameters
anotherURLOptional. Will overwrite the url value.
Returns
New request instance, having all data, header and other properties copied.

◆ sendAsync()

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.

Parameters
callbackReceive progress and result with this callback.
clientDataYour custom data with the callback.
tempFolderPathIf not NULL, the server response body will be written to a temporary file (into this folder) instead of memory.
flushAfterWriteTrue to fflush() after every file write (useful for progressive downloads).
logUse this for debugging purposes to see the full HTTP log.

◆ sendBlocking()

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.

Parameters
callbackReceive progress or perform custom data handling with this callback.
clientDataYour custom data with the callback.
tempFolderPathIf not NULL, the server response body will be written to a temporary file (into this folder) instead of memory.
flushAfterWriteTrue to fflush() after every file write (useful for progressive downloads).
logUse this for debugging purposes to see the full HTTP log.
Returns
An HTTP response object. Don't forget to destruct it after processing, to prevent memory leaks.

◆ setCustomContent()

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.

Parameters
contentTypeHeaderValueContent type of the custom content. Example: "text/css".
contentCustom body.
contentLengthBytesThe size of the custom body in bytes (not including trailing zero, you can use strlen for example).

◆ setURL() [1/3]

void Superpowered::httpRequest::setURL ( char *  url)

Sets the url (and discards the old one).

Example: request->setURL(myURL);

Parameters
urlThe relative url.

◆ setURL() [2/3]

void Superpowered::httpRequest::setURL ( const char *  url)

Sets the url (and discards the old one).

Example: request->setURL("https://superpowered.com");

Parameters
urlThe relative url.

◆ setURL() [3/3]

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);

Parameters
urlMaxSizeBytesThe maximum predicted memory usage of the result string. Can be any safe number.
formatContains 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().

Member Data Documentation

◆ customContent

char* Superpowered::httpRequest::customContent

Custom body for the query. Can not be used with fileToPostPath.

◆ customContentLengthBytes

unsigned int Superpowered::httpRequest::customContentLengthBytes

The size in bytes of customContent.

◆ customContentTypeHeaderValue

char* Superpowered::httpRequest::customContentTypeHeaderValue

Content type of the custom content. Example: "text/css".

◆ customDownloadHandling

bool Superpowered::httpRequest::customDownloadHandling

Set to true to use your own data handling/file writing. Default: false.

◆ data

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.

◆ disableHttpCacheControl

bool Superpowered::httpRequest::disableHttpCacheControl

Disable HTTP caching by adding a Cache-Control: no-cache, no-store, must-revalidate header. Default: true.

◆ fileToPostName

char* Superpowered::httpRequest::fileToPostName

Optional filename for fileToPostPath. If NULL, will use the file name in fileToPostPath. NULL by default.

◆ fileToPostPath

char* Superpowered::httpRequest::fileToPostPath

Path to a file to send in the body of the query. Typically used with POST requests. NULL by default.

◆ headers

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.

◆ maximumBytesToReceive

unsigned int Superpowered::httpRequest::maximumBytesToReceive

Maximum bytes to receive (will interrupt the transfer if reached). Default: 1024 * 1024 * 100 (100 megabytes)

◆ maximumNumberOfRedirects

unsigned int Superpowered::httpRequest::maximumNumberOfRedirects

Maximum number of redirects. Default: 20.

◆ method

const char* Superpowered::httpRequest::method

HTTP method. Default: "GET".

◆ timeoutSeconds

unsigned int Superpowered::httpRequest::timeoutSeconds

Timeout in seconds. Default: 60.

◆ url

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.


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