Implements the user-facing functions in core_http_client.h. More...
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "core_http_client.h"
#include "core_http_client_private.h"
Functions | |
static uint32_t | getZeroTimestampMs (void) |
When HTTPResponse_t.getTime is set to NULL in HTTPClient_Send then this function will replace that field. | |
static HTTPStatus_t | addContentLengthHeader (HTTPRequestHeaders_t *pRequestHeaders, size_t contentLength) |
Adds the Content-Length header field and value to the pRequestHeaders . | |
static HTTPStatus_t | sendHttpBody (const TransportInterface_t *pTransport, HTTPClient_GetCurrentTimeFunc_t getTimestampMs, const uint8_t *pRequestBodyBuf, size_t reqBodyBufLen) |
Send the HTTP body over the transport send interface. | |
static char * | httpHeaderStrncpy (char *pDest, const char *pSrc, size_t len, uint8_t isField) |
A strncpy replacement with HTTP header validation. | |
static HTTPStatus_t | addHeader (HTTPRequestHeaders_t *pRequestHeaders, const char *pField, size_t fieldLen, const char *pValue, size_t valueLen) |
Write header based on parameters. This method also adds a trailing "\r\n". If a trailing "\r\n" already exists in the HTTP header, this method backtracks in order to write over it and updates the length accordingly. | |
static HTTPStatus_t | addRangeHeader (HTTPRequestHeaders_t *pRequestHeaders, int32_t rangeStartOrlastNbytes, int32_t rangeEnd) |
Add the byte range request header to the request headers store in HTTPRequestHeaders_t.pBuffer once all the parameters are validated. | |
static HTTPStatus_t | getFinalResponseStatus (HTTPParsingState_t parsingState, size_t totalReceived, size_t responseBufferLen) |
Get the status of the HTTP response given the parsing state and how much data is in the response buffer. | |
static HTTPStatus_t | sendHttpRequest (const TransportInterface_t *pTransport, HTTPClient_GetCurrentTimeFunc_t getTimestampMs, HTTPRequestHeaders_t *pRequestHeaders, const uint8_t *pRequestBodyBuf, size_t reqBodyBufLen, uint32_t sendFlags) |
Send the HTTP request over the network. | |
static uint8_t | convertInt32ToAscii (int32_t value, char *pBuffer, size_t bufferLength) |
Converts an integer value to its ASCII representation in the passed buffer. | |
static HTTPStatus_t | writeRequestLine (HTTPRequestHeaders_t *pRequestHeaders, const char *pMethod, size_t methodLen, const char *pPath, size_t pathLen) |
This method writes the request line (first line) of the HTTP Header into HTTPRequestHeaders_t.pBuffer and updates length accordingly. | |
static HTTPStatus_t | findHeaderInResponse (const uint8_t *pBuffer, size_t bufferLen, const char *pField, size_t fieldLen, const char **pValueLoc, size_t *pValueLen) |
Find the specified header field in the response buffer. | |
static int | findHeaderFieldParserCallback (llhttp_t *pHttpParser, const char *pFieldLoc, size_t fieldLen) |
The "on_header_field" callback for the HTTP parser used by the findHeaderInResponse function. The callback checks whether the parser header field matched the header being searched for, and sets a flag to represent reception of the header accordingly. | |
static int | findHeaderValueParserCallback (llhttp_t *pHttpParser, const char *pValueLoc, size_t valueLen) |
The "on_header_value" callback for the HTTP parser used by the findHeaderInResponse function. The callback sets the user-provided output parameters for header value if the requested header's field was found in the findHeaderFieldParserCallback function. | |
static int | findHeaderOnHeaderCompleteCallback (llhttp_t *pHttpParser) |
The "on_header_complete" callback for the HTTP parser used by the findHeaderInResponse function. | |
static void | initializeParsingContextForFirstResponse (HTTPParsingContext_t *pParsingContext, const HTTPRequestHeaders_t *pRequestHeaders) |
Initialize the parsing context for parsing a response fresh from the server. | |
static HTTPStatus_t | parseHttpResponse (HTTPParsingContext_t *pParsingContext, HTTPResponse_t *pResponse, size_t parseLen) |
Parses the response buffer in pResponse . | |
static int | httpParserOnMessageBeginCallback (llhttp_t *pHttpParser) |
Callback invoked during llhttp_execute() to indicate the start of the HTTP response message. | |
static int | httpParserOnStatusCallback (llhttp_t *pHttpParser, const char *pLoc, size_t length) |
Callback invoked during llhttp_execute() when the HTTP response status-code and its associated reason-phrase are found. | |
static int | httpParserOnStatusCompleteCallback (llhttp_t *pHttpParser) |
Callback invoked during llhttp_execute() when the HTTP response status parsing is complete. | |
static int | httpParserOnHeaderFieldCallback (llhttp_t *pHttpParser, const char *pLoc, size_t length) |
Callback invoked during llhttp_execute() when an HTTP response header field is found. | |
static int | httpParserOnHeaderValueCallback (llhttp_t *pHttpParser, const char *pLoc, size_t length) |
Callback invoked during llhttp_execute() when an HTTP response header value is found. | |
static int | httpParserOnHeadersCompleteCallback (llhttp_t *pHttpParser) |
Callback invoked during llhttp_execute() when the end of the headers are found. | |
static int | httpParserOnBodyCallback (llhttp_t *pHttpParser, const char *pLoc, size_t length) |
Callback invoked during llhttp_execute() when the HTTP response body is found. | |
static int | httpParserOnMessageCompleteCallback (llhttp_t *pHttpParser) |
Callback invoked during llhttp_execute() to indicate the the completion of an HTTP response message. | |
static void | processCompleteHeader (HTTPParsingContext_t *pParsingContext) |
When a complete header is found the HTTP response header count increases and the application is notified. | |
static HTTPStatus_t | processLlhttpError (const llhttp_t *pHttpParser) |
When parsing is complete an error could be indicated in pHttpParser->error. This function translates that error into a library specific error code. | |
static int8_t | caseInsensitiveStringCmp (const char *str1, const char *str2, size_t n) |
Compares at most the first n bytes of str1 and str2 without case sensitivity and n must be less than the actual size of either string. | |
HTTPStatus_t | HTTPClient_InitializeRequestHeaders (HTTPRequestHeaders_t *pRequestHeaders, const HTTPRequestInfo_t *pRequestInfo) |
Initialize the request headers, stored in HTTPRequestHeaders_t.pBuffer, with initial configurations from HTTPRequestInfo_t. This method is expected to be called before sending a new request. | |
HTTPStatus_t | HTTPClient_AddHeader (HTTPRequestHeaders_t *pRequestHeaders, const char *pField, size_t fieldLen, const char *pValue, size_t valueLen) |
Add a header to the request headers stored in HTTPRequestHeaders_t.pBuffer. | |
HTTPStatus_t | HTTPClient_AddRangeHeader (HTTPRequestHeaders_t *pRequestHeaders, int32_t rangeStartOrlastNbytes, int32_t rangeEnd) |
Add the byte range request header to the request headers store in HTTPRequestHeaders_t.pBuffer. | |
HTTPStatus_t | HTTPClient_SendHttpData (const TransportInterface_t *pTransport, HTTPClient_GetCurrentTimeFunc_t getTimestampMs, const uint8_t *pData, size_t dataLen) |
Send the request body in pRequestBodyBuf over the transport. | |
HTTPStatus_t | HTTPClient_SendHttpHeaders (const TransportInterface_t *pTransport, HTTPClient_GetCurrentTimeFunc_t getTimestampMs, HTTPRequestHeaders_t *pRequestHeaders, size_t reqBodyLen, uint32_t sendFlags) |
Send the request headers in pRequestHeaders over the transport. | |
HTTPStatus_t | HTTPClient_ReceiveAndParseHttpResponse (const TransportInterface_t *pTransport, HTTPResponse_t *pResponse, const HTTPRequestHeaders_t *pRequestHeaders) |
Receive the HTTP response from the network and parse it. | |
HTTPStatus_t | HTTPClient_Send (const TransportInterface_t *pTransport, HTTPRequestHeaders_t *pRequestHeaders, const uint8_t *pRequestBodyBuf, size_t reqBodyBufLen, HTTPResponse_t *pResponse, uint32_t sendFlags) |
Send the request headers in HTTPRequestHeaders_t.pBuffer and request body in pRequestBodyBuf over the transport. The response is received in HTTPResponse_t.pBuffer. | |
HTTPStatus_t | HTTPClient_ReadHeader (const HTTPResponse_t *pResponse, const char *pField, size_t fieldLen, const char **pValueLoc, size_t *pValueLen) |
Read a header from a buffer containing a complete HTTP response. This will return the location of the response header value in the HTTPResponse_t.pBuffer buffer. | |
const char * | HTTPClient_strerror (HTTPStatus_t status) |
Error code to string conversion utility for HTTP Client library. | |
Implements the user-facing functions in core_http_client.h.
|
static |
When HTTPResponse_t.getTime is set to NULL in HTTPClient_Send then this function will replace that field.
|
static |
Adds the Content-Length header field and value to the pRequestHeaders
.
[in] | pRequestHeaders | Request header buffer information. |
[in] | contentLength | The Content-Length header value to write. |
|
static |
Send the HTTP body over the transport send interface.
[in] | pTransport | Transport interface. |
[in] | getTimestampMs | Function to retrieve a timestamp in milliseconds. |
[in] | pRequestBodyBuf | Request body buffer. |
[in] | reqBodyBufLen | Length of the request body buffer. |
|
static |
A strncpy replacement with HTTP header validation.
This function checks for \r
and \n
in the pSrc
while copying. This function checks for :
in the pSrc
, if isField
is set to 1.
[in] | pDest | The destination buffer to copy to. |
[in] | pSrc | The source buffer to copy from. |
[in] | len | The length of pSrc to copy to pDest. |
[in] | isField | Set to 0 to indicate that pSrc is a field. Set to 1 to indicate that pSrc is a value. |
pDest
if the copy was successful, NULL otherwise.
|
static |
Write header based on parameters. This method also adds a trailing "\r\n". If a trailing "\r\n" already exists in the HTTP header, this method backtracks in order to write over it and updates the length accordingly.
[in] | pRequestHeaders | Request header buffer information. |
[in] | pField | The ISO 8859-1 encoded header field name to write. |
[in] | fieldLen | The byte length of the header field name. |
[in] | pValue | The ISO 8859-1 encoded header value to write. |
[in] | valueLen | The byte length of the header field value. |
|
static |
Add the byte range request header to the request headers store in HTTPRequestHeaders_t.pBuffer once all the parameters are validated.
[in] | pRequestHeaders | Request header buffer information. |
[in] | rangeStartOrlastNbytes | Represents either the starting byte for a range OR the last N number of bytes in the requested file. |
[in] | rangeEnd | The ending range for the requested file. For end of file byte in Range Specifications 2. and 3., HTTP_RANGE_REQUEST_END_OF_FILE should be passed. |
|
static |
Get the status of the HTTP response given the parsing state and how much data is in the response buffer.
[in] | parsingState | State of the parsing on the HTTP response. |
[in] | totalReceived | The amount of network data received in the response buffer. |
[in] | responseBufferLen | The length of the response buffer. |
|
static |
Send the HTTP request over the network.
[in] | pTransport | Transport interface. |
[in] | getTimestampMs | Function to retrieve a timestamp in milliseconds. |
[in] | pRequestHeaders | Request headers to send over the network. |
[in] | pRequestBodyBuf | Request body buffer to send over the network. |
[in] | reqBodyBufLen | Length of the request body buffer. |
[in] | sendFlags | Application provided flags to HTTPClient_Send. |
|
static |
Converts an integer value to its ASCII representation in the passed buffer.
[in] | value | The value to convert to ASCII. |
[out] | pBuffer | The buffer to store the ASCII representation of the integer. |
[in] | bufferLength | The length of pBuffer. |
pBuffer
.
|
static |
This method writes the request line (first line) of the HTTP Header into HTTPRequestHeaders_t.pBuffer and updates length accordingly.
pRequestHeaders | Request header buffer information. |
pMethod | The HTTP request method e.g. "GET", "POST", "PUT", or "HEAD". |
methodLen | The byte length of the request method. |
pPath | The Request-URI to the objects of interest, e.g. "/path/to/item.txt". |
pathLen | The byte length of the request path. |
|
static |
Find the specified header field in the response buffer.
[in] | pBuffer | The response buffer to parse. |
[in] | bufferLen | The length of the response buffer to parse. |
[in] | pField | The header field to search for. |
[in] | fieldLen | The length of pField. |
[out] | pValueLoc | The location of the the header value found in pBuffer. |
[out] | pValueLen | The length of pValue. |
|
static |
The "on_header_field" callback for the HTTP parser used by the findHeaderInResponse function. The callback checks whether the parser header field matched the header being searched for, and sets a flag to represent reception of the header accordingly.
[in] | pHttpParser | Parsing object containing state and callback context. |
[in] | pFieldLoc | The location of the parsed header field in the response buffer. |
[in] | fieldLen | The length of the header field. |
|
static |
The "on_header_value" callback for the HTTP parser used by the findHeaderInResponse function. The callback sets the user-provided output parameters for header value if the requested header's field was found in the findHeaderFieldParserCallback function.
[in] | pHttpParser | Parsing object containing state and callback context. |
[in] | pValueLoc | The location of the parsed header value in the response buffer. |
[in] | valueLen | The length of the header value. |
|
static |
The "on_header_complete" callback for the HTTP parser used by the findHeaderInResponse function.
This callback will only be invoked if the requested header is not found in the response. This callback is used to signal the parser to halt execution if the requested header is not found.
[in] | pHttpParser | Parsing object containing state and callback context. |
|
static |
Initialize the parsing context for parsing a response fresh from the server.
[in] | pParsingContext | The parsing context to initialize. |
[in] | pRequestHeaders | Request headers for the corresponding HTTP request. |
|
static |
Parses the response buffer in pResponse
.
This function may be invoked multiple times for different parts of the the HTTP response. The state of what was last parsed in the response is kept in pParsingContext
.
[in,out] | pParsingContext | The response parsing state. |
[in,out] | pResponse | The response information to be updated. |
[in] | parseLen | The next length to parse in pResponse->pBuffer. |
|
static |
Callback invoked during llhttp_execute() to indicate the start of the HTTP response message.
This callback is invoked when an "H" in the "HTTP/1.1" that starts a response is found.
[in] | pHttpParser | Parsing object containing state and callback context. |
|
static |
Callback invoked during llhttp_execute() when the HTTP response status-code and its associated reason-phrase are found.
[in] | pHttpParser | Parsing object containing state and callback context. |
[in] | pLoc | Location of the HTTP response reason-phrase string in the response message buffer. |
[in] | length | Length of the HTTP response status code string. |
|
static |
Callback invoked during llhttp_execute() when the HTTP response status parsing is complete.
[in] | pHttpParser | Parsing object containing state and callback context. |
|
static |
Callback invoked during llhttp_execute() when an HTTP response header field is found.
If only part of the header field was found, then parsing of the next part of the response message will invoke this callback in succession.
[in] | pHttpParser | Parsing object containing state and callback context. |
[in] | pLoc | Location of the header field string in the response message buffer. |
[in] | length | Length of the header field. |
|
static |
Callback invoked during llhttp_execute() when an HTTP response header value is found.
This header value corresponds to the header field that was found in the immediately preceding httpParserOnHeaderFieldCallback().
If only part of the header value was found, then parsing of the next part of the response message will invoke this callback in succession.
[in] | pHttpParser | Parsing object containing state and callback context. |
[in] | pLoc | Location of the header value in the response message buffer. |
[in] | length | Length of the header value. |
|
static |
Callback invoked during llhttp_execute() when the end of the headers are found.
The end of the headers is signaled in a HTTP response message by another "\r\n" after the final header line.
[in] | pHttpParser | Parsing object containing state and callback context. |
|
static |
Callback invoked during llhttp_execute() when the HTTP response body is found.
If only part of the response body was found, then parsing of the next part of the response message will invoke this callback in succession.
This callback will be also invoked in succession if the response body is of type "Transfer-Encoding: chunked". This callback will be invoked after each chunk header.
The follow is an example of a Transfer-Encoding chunked response:
The first invocation of this callback will contain pLoc
= "Hello World!" and length
= 13. The second invocation of this callback will contain pLoc
= "I am a " and length
= 7. The third invocation of this callback will contain pLoc
= "developer." and length
= 10.
[in] | pHttpParser | Parsing object containing state and callback context. |
[in] | pLoc | - Pointer to the body string in the response message buffer. |
[in] | length | - The length of the body found. |
|
static |
Callback invoked during llhttp_execute() to indicate the the completion of an HTTP response message.
When there is no response body, the end of the response message is when the headers end. This is indicated by another "\r\n" after the final header line.
When there is response body, the end of the response message is when the full "Content-Length" value is parsed following the end of the headers. If there is no Content-Length header, then llhttp_execute() expects a zero length-ed parsing data to indicate the end of the response.
For a "Transfer-Encoding: chunked" type of response message, the complete response message is signaled by a terminating chunk header with length zero.
See https://github.com/nodejs/llhttp for more information.
[in] | pHttpParser | Parsing object containing state and callback context. |
|
static |
When a complete header is found the HTTP response header count increases and the application is notified.
This function is invoked only in callbacks that could follow httpParserOnHeaderValueCallback. These callbacks are httpParserOnHeaderFieldCallback and httpParserOnHeadersCompleteCallback. A header field and value is not is not known to be complete until httpParserOnHeaderValueCallback is not called in succession.
[in] | pParsingContext | Parsing state containing information to notify the application of a complete header. |
|
static |
When parsing is complete an error could be indicated in pHttpParser->error. This function translates that error into a library specific error code.
[in] | pHttpParser | Third-party HTTP parsing context. |
|
static |
Compares at most the first n bytes of str1 and str2 without case sensitivity and n must be less than the actual size of either string.
[in] | str1 | First string to be compared. |
[in] | str2 | Second string to be compared. |
[in] | n | The maximum number of characters to be compared. |
HTTPStatus_t HTTPClient_InitializeRequestHeaders | ( | HTTPRequestHeaders_t * | pRequestHeaders, |
const HTTPRequestInfo_t * | pRequestInfo | ||
) |
Initialize the request headers, stored in HTTPRequestHeaders_t.pBuffer, with initial configurations from HTTPRequestInfo_t. This method is expected to be called before sending a new request.
Upon return, HTTPRequestHeaders_t.headersLen will be updated with the number of bytes written.
Each line in the header is listed below and written in this order: <HTTPRequestInfo_t.pMethod> <HTTPRequestInfo_t.pPath> <HTTP_PROTOCOL_VERSION> User-Agent: <HTTP_USER_AGENT_VALUE> Host: <HTTPRequestInfo_t.pHost>
Note that "Connection" header can be added and set to "keep-alive" by activating the HTTP_REQUEST_KEEP_ALIVE_FLAG in HTTPRequestInfo_t.reqFlags.
[in] | pRequestHeaders | Request header buffer information. |
[in] | pRequestInfo | Initial request header configurations. |
Example
HTTPStatus_t HTTPClient_AddHeader | ( | HTTPRequestHeaders_t * | pRequestHeaders, |
const char * | pField, | ||
size_t | fieldLen, | ||
const char * | pValue, | ||
size_t | valueLen | ||
) |
Add a header to the request headers stored in HTTPRequestHeaders_t.pBuffer.
Upon return, pRequestHeaders->headersLen will be updated with the number of bytes written.
Headers are written in the following format:
The trailing \r\n
that denotes the end of the header lines is overwritten, if it already exists in the buffer.
\r
, \n
, and :
are not present in pValue
or pField
. :
is allowed in pValue
.[in] | pRequestHeaders | Request header buffer information. |
[in] | pField | The header field name to write. The data should be ISO 8859-1 (Latin-1) encoded per the HTTP standard, but the API does not perform the character set validation. |
[in] | fieldLen | The byte length of the header field name. |
[in] | pValue | The header value to write. The data should be ISO 8859-1 (Latin-1) encoded per the HTTP standard, but the API does not perform the character set validation. |
[in] | valueLen | The byte length of the header field value. |
pField
or pValue
.)Example
HTTPStatus_t HTTPClient_AddRangeHeader | ( | HTTPRequestHeaders_t * | pRequestHeaders, |
int32_t | rangeStartOrlastNbytes, | ||
int32_t | rangeEnd | ||
) |
Add the byte range request header to the request headers store in HTTPRequestHeaders_t.pBuffer.
For example, if requesting for the first 1kB of a file the following would be written: Range: bytes=0-1023\r\n\r\n
.
The trailing \r\n
that denotes the end of the header lines is overwritten, if it already exists in the buffer.
There are 3 different forms of range specification, determined by the combination of rangeStartOrLastNBytes and rangeEnd parameter values:
Range: bytes=0-1023\r\n
for requesting bytes in the range [0, 1023].rangeStartOrlastNbytes
. rangeStartOrlastNbytes
should be negative and rangeEnd
should be HTTP_RANGE_REQUEST_END_OF_FILE. Example request header line: Range: bytes=-512\r\n
for requesting the last 512 bytes (or bytes in the range [512, 1023] for a 1KB sized file).rangeStartOrlastNbytes
. rangeStartOrlastNbytes
should be >= 0 and rangeEnd
should be HTTP_RANGE_REQUEST_END_OF_FILE.Range: bytes=256-\r\n
for requesting all bytes after and including byte 256 (or bytes in the range [256,1023] for a 1kB sized file).[in] | pRequestHeaders | Request header buffer information. |
[in] | rangeStartOrlastNbytes | Represents either the starting byte for a range OR the last N number of bytes in the requested file. |
[in] | rangeEnd | The ending range for the requested file. For end of file byte in Range Specifications 2. and 3., HTTP_RANGE_REQUEST_END_OF_FILE should be passed. |
rangeStartOrlastNbytes
and rangeEnd
parameter combination is invalid. HTTPInsufficientMemory, if the passed HTTPRequestHeaders_t.pBuffer contains insufficient remaining memory for storing the range request. HTTPStatus_t HTTPClient_SendHttpData | ( | const TransportInterface_t * | pTransport, |
HTTPClient_GetCurrentTimeFunc_t | getTimestampMs, | ||
const uint8_t * | pData, | ||
size_t | dataLen | ||
) |
Send the request body in pRequestBodyBuf
over the transport.
[in] | pTransport | Transport interface, see TransportInterface_t for more information. |
[in] | getTimestampMs | Function to retrieve a timestamp in milliseconds. |
[in] | pData | HTTP request data to send. |
[in] | dataLen | HTTP request data length. |
HTTPStatus_t HTTPClient_SendHttpHeaders | ( | const TransportInterface_t * | pTransport, |
HTTPClient_GetCurrentTimeFunc_t | getTimestampMs, | ||
HTTPRequestHeaders_t * | pRequestHeaders, | ||
size_t | reqBodyLen, | ||
uint32_t | sendFlags | ||
) |
Send the request headers in pRequestHeaders
over the transport.
If HTTP_SEND_DISABLE_CONTENT_LENGTH_FLAG is not set in parameter sendFlags
, then the Content-Length to be sent to the server is automatically written to pRequestHeaders
. The Content-Length will not be written when there is no request body. If there is not enough room in the buffer to write the Content-Length then HTTPInsufficientMemory is returned. Please see HTTP_MAX_CONTENT_LENGTH_HEADER_LENGTH for the maximum Content-Length header field and value that could be written to the buffer.
The application should close the connection with the server if any of the following errors are returned:
[in] | pTransport | Transport interface, see TransportInterface_t for more information. |
[in] | getTimestampMs | Function to retrieve a timestamp in milliseconds. |
[in] | pRequestHeaders | Request configuration containing the buffer of headers to send. |
[in] | reqBodyLen | The length of the request entity in bytes. |
[in] | sendFlags | Flags which modify the behavior of this function. Please see HTTPClient_Send Flags for more information. |
HTTPStatus_t HTTPClient_ReceiveAndParseHttpResponse | ( | const TransportInterface_t * | pTransport, |
HTTPResponse_t * | pResponse, | ||
const HTTPRequestHeaders_t * | pRequestHeaders | ||
) |
Receive the HTTP response from the network and parse it.
[in] | pTransport | Transport interface, see TransportInterface_t for more information. |
[in] | pResponse | The response message and some notable response parameters will be returned here on success. |
[in] | pRequestHeaders | Request configuration containing the buffer of headers to send. |
HTTPStatus_t HTTPClient_Send | ( | const TransportInterface_t * | pTransport, |
HTTPRequestHeaders_t * | pRequestHeaders, | ||
const uint8_t * | pRequestBodyBuf, | ||
size_t | reqBodyBufLen, | ||
HTTPResponse_t * | pResponse, | ||
uint32_t | sendFlags | ||
) |
Send the request headers in HTTPRequestHeaders_t.pBuffer and request body in pRequestBodyBuf
over the transport. The response is received in HTTPResponse_t.pBuffer.
If HTTP_SEND_DISABLE_CONTENT_LENGTH_FLAG is not set in parameter sendFlags
, then the Content-Length to be sent to the server is automatically written to pRequestHeaders
. The Content-Length will not be written when there is no request body. If there is not enough room in the buffer to write the Content-Length then HTTPInsufficientMemory is returned. Please see HTTP_MAX_CONTENT_LENGTH_HEADER_LENGTH for the maximum Content-Length header field and value that could be written to the buffer.
The application should close the connection with the server if any of the following errors are returned:
The pResponse
returned is valid only if this function returns HTTPSuccess.
[in] | pTransport | Transport interface, see TransportInterface_t for more information. |
[in] | pRequestHeaders | Request configuration containing the buffer of headers to send. |
[in] | pRequestBodyBuf | Optional Request entity body. Set to NULL if there is no request body. |
[in] | reqBodyBufLen | The length of the request entity in bytes. |
[in] | pResponse | The response message and some notable response parameters will be returned here on success. |
[in] | sendFlags | Flags which modify the behavior of this function. Please see HTTPClient_Send Flags for more information. |
Example
HTTPStatus_t HTTPClient_ReadHeader | ( | const HTTPResponse_t * | pResponse, |
const char * | pField, | ||
size_t | fieldLen, | ||
const char ** | pValueLoc, | ||
size_t * | pValueLen | ||
) |
Read a header from a buffer containing a complete HTTP response. This will return the location of the response header value in the HTTPResponse_t.pBuffer buffer.
The location, within HTTPResponse_t.pBuffer, of the value found, will be returned in pValue
. If the header value is empty for the found pField
, then this function will return HTTPSuccess, and set the values for pValueLoc
and pValueLen
as NULL and zero respectively. According to RFC 2616, it is not invalid to have an empty value for some header fields.
[in] | pResponse | The buffer containing the completed HTTP response. |
[in] | pField | The header field name to read. |
[in] | fieldLen | The length of the header field name in bytes. |
[out] | pValueLoc | This will be populated with the location of the header value in the response buffer, HTTPResponse_t.pBuffer. |
[out] | pValueLen | This will be populated with the length of the header value in bytes. |
Example
const char * HTTPClient_strerror | ( | HTTPStatus_t | status | ) |
Error code to string conversion utility for HTTP Client library.
[in] | status | The status code to convert to a string. |