FreeRTOS: HTTPS Client
HTTPS Client v1.0.0 library
Return to main page ↑
IotHttpsClient_ReadContentLength

Retrieve the HTTPS response content length.

If the "Content-Length" header is available in IotHttpsResponseInfo_t.userBuffer, this routine extracts that value. In some cases the "Content-Length" header is not available. This could be because the server sent a multi-part encoded response (For example, "Transfer-Encoding: chunked") or the "Content-Length" header was far down in the list of response headers and could not fit into the header buffer configured in IotHttpsResponseInfo_t.userBuffer. Please see responseUserBufferMinimumSize for information about sizing the IotHttpsResponseInfo_t.userBuffer.

In the asynchronous request process, the Content-Length is not available until the IotHttpsClientCallbacks_t.readReadyCallback. Before the IotHttpsClientCallbacks_t.readReadyCallback is invoked, the headers are read into as much as can fit in in the header buffer space of IotHttpsResponseInfo_t.userBuffer. Example Asynchronous Code

void applicationDefined_readReadyCallback(void * pPrivData, IotHttpsResponseHandle_t respHandle, IotHttpsReturnCode_t rc, uint16_t status)
{
uint8_t * readBuffer = NULL;
uint32_t contentLength = 0;
IotHttpsClient_ReadContentLength(respHandle, &contentLength);
readBuffer = (uint8_t*)malloc(contentLength);
...
}

In a synchronous request process, the Content-Length is available after IotHttpsClient_SendSync has returned successfully. Example Synchronous Code

...
IotHttpsClient_SendSync(connHandle, reqHandle, &respHandle, &respInfo, timeout);
uint32_t contentLength = 0;
IotHttpsClient_ReadContentLength(respHandle, &contentLength);
printf("Content-Length: %u", (unsigned int)contentLength);
...
Parameters
[in]respHandle- Unique handle representing the HTTPS response.
[out]pContentLength- Integer content length from the Content-Length header from the server. If the content length is not found this will be 0.
Returns
One of the following:
IotHttpsClient_ReadContentLength
IotHttpsReturnCode_t IotHttpsClient_ReadContentLength(IotHttpsResponseHandle_t respHandle, uint32_t *pContentLength)
Retrieve the HTTPS response content length.
Definition: iot_https_client.c:3364
IotHttpsResponseHandle_t
struct _httpsResponse * IotHttpsResponseHandle_t
Opaque handle of an HTTP response.
Definition: iot_https_types.h:280
IotHttpsReturnCode_t
IotHttpsReturnCode_t
Return codes of HTTPS Client functions.
Definition: iot_https_types.h:294