coreHTTP  v2.0.2
HTTP/1.1 Client Library
HTTPClient_InitializeRequestHeaders

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.

Parameters
[in]pRequestHeadersRequest header buffer information.
[in]pRequestInfoInitial request header configurations.
Returns
One of the following:

Example

HTTPStatus_t httpLibraryStatus = HTTPSuccess;
// Declare an HTTPRequestHeaders_t and HTTPRequestInfo_t.
HTTPRequestHeaders_t requestHeaders = { 0 };
HTTPRequestInfo_t requestInfo = { 0 };
// A buffer that will fit the Request-Line, the User-Agent header line, and
// the Host header line.
uint8_t requestHeaderBuffer[ 256 ] = { 0 };
// Set a buffer to serialize request headers to.
requestHeaders.pBuffer = requestHeaderBuffer;
requestHeaders.bufferLen = 256;
// Set the Method, Path, and Host in the HTTPRequestInfo_t.
requestInfo.pMethod = HTTP_METHOD_GET;
requestInfo.methodLen = sizeof( HTTP_METHOD_GET ) - 1U;
requestInfo.pPath = "/html/rfc2616"
requestInfo.pathLen = sizeof( "/html/rfc2616" ) - 1U;
requestInfo.pHost = "tools.ietf.org"
requestInfo.hostLen = sizeof( "tools.ietf.org" ) - 1U;
httpLibraryStatus = HTTPClient_InitializeRequestHeaders( &requestHeaders,
&requestInfo );
HTTPSuccess
@ HTTPSuccess
The HTTP Client library function completed successfully.
Definition: core_http_client.h:173
HTTPRequestHeaders_t
Represents header data that will be sent in an HTTP request.
Definition: core_http_client.h:329
HTTPRequestInfo_t::pPath
const char * pPath
The Request-URI to the objects of interest, e.g. "/path/to/item.txt".
Definition: core_http_client.h:370
HTTP_METHOD_GET
#define HTTP_METHOD_GET
Definition: core_http_client.h:60
HTTPRequestInfo_t::pMethod
const char * pMethod
The HTTP request method e.g. "GET", "POST", "PUT", or "HEAD".
Definition: core_http_client.h:364
HTTPRequestInfo_t::reqFlags
uint32_t reqFlags
Flags to activate other request header configurations.
Definition: core_http_client.h:386
HTTPRequestHeaders_t::bufferLen
size_t bufferLen
Definition: core_http_client.h:345
HTTPClient_InitializeRequestHeaders
HTTPStatus_t HTTPClient_InitializeRequestHeaders(HTTPRequestHeaders_t *pRequestHeaders, const HTTPRequestInfo_t *pRequestInfo)
Initialize the request headers, stored in HTTPRequestHeaders_t.pBuffer, with initial configurations f...
Definition: core_http_client.c:1557
HTTP_REQUEST_KEEP_ALIVE_FLAG
#define HTTP_REQUEST_KEEP_ALIVE_FLAG
Set this flag to indicate that the request is for a persistent connection.
Definition: core_http_client.h:112
HTTPRequestInfo_t::hostLen
size_t hostLen
Definition: core_http_client.h:379
HTTPStatus_t
HTTPStatus_t
The HTTP Client library return status.
Definition: core_http_client.h:162
HTTPRequestInfo_t::pHost
const char * pHost
The server's host name, e.g. "my-storage.my-cloud.com".
Definition: core_http_client.h:378
HTTPRequestInfo_t
Configurations of the initial request headers.
Definition: core_http_client.h:360
HTTPRequestInfo_t::methodLen
size_t methodLen
Definition: core_http_client.h:365
HTTPRequestHeaders_t::pBuffer
uint8_t * pBuffer
Buffer to hold the raw HTTP request headers.
Definition: core_http_client.h:344
HTTPRequestInfo_t::pathLen
size_t pathLen
Definition: core_http_client.h:371