coreHTTP v3.1.1
HTTP/1.1 Client Library
 
Loading...
Searching...
No Matches
HTTPClient_InitializeRequestHeaders
const HTTPRequestInfo_t * pRequestInfo );
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:1589
HTTPStatus_t
The HTTP Client library return status.
Definition: core_http_client.h:196
Represents header data that will be sent in an HTTP request.
Definition: core_http_client.h:365
Configurations of the initial request headers.
Definition: core_http_client.h:396

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 );
#define HTTP_METHOD_GET
Definition: core_http_client.h:62
@ HTTPSuccess
The HTTP Client library function completed successfully.
Definition: core_http_client.h:207
#define HTTP_REQUEST_KEEP_ALIVE_FLAG
Set this flag to indicate that the request is for a persistent connection.
Definition: core_http_client.h:114
size_t bufferLen
Definition: core_http_client.h:381
uint8_t * pBuffer
Buffer to hold the raw HTTP request headers.
Definition: core_http_client.h:380
uint32_t reqFlags
Flags to activate other request header configurations.
Definition: core_http_client.h:422
size_t methodLen
Definition: core_http_client.h:401
const char * pMethod
The HTTP request method e.g. "GET", "POST", "PUT", or "HEAD".
Definition: core_http_client.h:400
const char * pPath
The Request-URI to the objects of interest, e.g. "/path/to/item.txt".
Definition: core_http_client.h:406
const char * pHost
The server's host name, e.g. "my-storage.my-cloud.com".
Definition: core_http_client.h:414
size_t pathLen
Definition: core_http_client.h:407
size_t hostLen
Definition: core_http_client.h:415