coreHTTP v3.1.1
HTTP/1.1 Client Library
 
Loading...
Searching...
No Matches
core_http_client_private.h
Go to the documentation of this file.
1/*
2 * coreHTTP v3.1.1
3 * Copyright (C) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
30#ifndef CORE_HTTP_CLIENT_PRIVATE_H_
31#define CORE_HTTP_CLIENT_PRIVATE_H_
32
37#ifndef LLHTTP_STRICT_MODE
38 #define LLHTTP_STRICT_MODE 0
39#endif
42/* Third-party llhttp include. */
43#include "llhttp.h"
44
45/* *INDENT-OFF* */
46#ifdef __cplusplus
47 extern "C" {
48#endif
49/* *INDENT-ON* */
50
54#define HTTP_PROTOCOL_VERSION "HTTP/1.1"
55#define HTTP_PROTOCOL_VERSION_LEN ( sizeof( HTTP_PROTOCOL_VERSION ) - 1U )
60#define HTTP_EMPTY_PATH "/"
61#define HTTP_EMPTY_PATH_LEN ( sizeof( HTTP_EMPTY_PATH ) - 1U )
63/* Constants for HTTP header formatting. */
64#define HTTP_HEADER_LINE_SEPARATOR "\r\n"
65#define HTTP_HEADER_LINE_SEPARATOR_LEN ( sizeof( HTTP_HEADER_LINE_SEPARATOR ) - 1U )
66#define HTTP_HEADER_END_INDICATOR "\r\n\r\n"
67#define HTTP_HEADER_END_INDICATOR_LEN ( sizeof( HTTP_HEADER_END_INDICATOR ) - 1U )
68#define HTTP_HEADER_FIELD_SEPARATOR ": "
69#define HTTP_HEADER_FIELD_SEPARATOR_LEN ( sizeof( HTTP_HEADER_FIELD_SEPARATOR ) - 1U )
70#define SPACE_CHARACTER ' '
71#define SPACE_CHARACTER_LEN ( 1U )
72#define DASH_CHARACTER '-'
73#define DASH_CHARACTER_LEN ( 1U )
75/* Constants for HTTP header copy checks. */
76#define CARRIAGE_RETURN_CHARACTER '\r'
77#define LINEFEED_CHARACTER '\n'
78#define COLON_CHARACTER ':'
84#define HTTP_HEADER_STRNCPY_IS_VALUE 0U
85
90#define HTTP_HEADER_STRNCPY_IS_FIELD 1U
91
92/* Constants for header fields added automatically during the request
93 * initialization. */
94#define HTTP_USER_AGENT_FIELD "User-Agent"
95#define HTTP_USER_AGENT_FIELD_LEN ( sizeof( HTTP_USER_AGENT_FIELD ) - 1U )
96#define HTTP_HOST_FIELD "Host"
97#define HTTP_HOST_FIELD_LEN ( sizeof( HTTP_HOST_FIELD ) - 1U )
98#define HTTP_USER_AGENT_VALUE_LEN ( sizeof( HTTP_USER_AGENT_VALUE ) - 1U )
100/* Constants for header fields added based on flags. */
101#define HTTP_CONNECTION_FIELD "Connection"
102#define HTTP_CONNECTION_FIELD_LEN ( sizeof( HTTP_CONNECTION_FIELD ) - 1U )
103#define HTTP_CONTENT_LENGTH_FIELD "Content-Length"
104#define HTTP_CONTENT_LENGTH_FIELD_LEN ( sizeof( HTTP_CONTENT_LENGTH_FIELD ) - 1U )
106/* Constants for header values added based on flags. */
107
108/* MISRA Ref 5.4.1 [Macro identifiers] */
109/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
110/* coverity[other_declaration] */
111#define HTTP_CONNECTION_KEEP_ALIVE_VALUE "keep-alive"
113/* MISRA Ref 5.4.2 [Macro identifiers] */
114/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
115/* coverity[misra_c_2012_rule_5_4_violation] */
116#define HTTP_CONNECTION_KEEP_ALIVE_VALUE_LEN ( sizeof( HTTP_CONNECTION_KEEP_ALIVE_VALUE ) - 1U )
118/* Constants relating to Range Requests. */
119
120/* MISRA Ref 5.4.3 [Macro identifiers] */
121/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
122/* coverity[other_declaration] */
123#define HTTP_RANGE_REQUEST_HEADER_FIELD "Range"
125/* MISRA Ref 5.4.4 [Macro identifiers] */
126/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
127/* coverity[misra_c_2012_rule_5_4_violation] */
128#define HTTP_RANGE_REQUEST_HEADER_FIELD_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_FIELD ) - 1U )
130/* MISRA Ref 5.4.5 [Macro identifiers] */
131/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
132/* coverity[other_declaration] */
133#define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX "bytes="
135/* MISRA Ref 5.4.6 [Macro identifiers] */
136/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
137/* coverity[misra_c_2012_rule_5_4_violation] */
138#define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX ) - 1U )
145#define MAX_INT32_NO_OF_DECIMAL_DIGITS 10U
146
153#define HTTP_MAX_RANGE_REQUEST_VALUE_LEN \
154 ( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN + MAX_INT32_NO_OF_DECIMAL_DIGITS + \
155 1U /* Dash character '-' */ + MAX_INT32_NO_OF_DECIMAL_DIGITS )
156
161#define LLHTTP_CONTINUE_PARSING 0
162
167#define LLHTTP_STOP_PARSING HPE_USER
168
173#define LLHTTP_PAUSE_PARSING HPE_PAUSED
174
179#define LLHTTP_STOP_PARSING_NO_BODY 1
180
188#define LLHTTP_STOP_PARSING_NO_HEADER 1
189
204#define HTTP_MINIMUM_REQUEST_LINE_LENGTH 16u
205
210typedef enum HTTPParsingState
211{
216
222typedef struct findHeaderContext
223{
224 const char * pField;
225 size_t fieldLen;
226 const char ** pValueLoc;
227 size_t * pValueLen;
228 uint8_t fieldFound;
229 uint8_t valueFound;
231
295typedef struct HTTPParsingContext
296{
297 llhttp_t llhttpParser;
298 llhttp_settings_t llhttpSettings;
303 const char * pBufferCur;
304 const char * pLastHeaderField;
306 const char * pLastHeaderValue;
309
310/* *INDENT-OFF* */
311#ifdef __cplusplus
312 }
313#endif
314/* *INDENT-ON* */
315
316#endif /* ifndef CORE_HTTP_CLIENT_PRIVATE_H_ */
HTTPParsingState_t
The state of the response message parsed after function parseHttpResponse returns.
Definition: core_http_client_private.h:211
@ HTTP_PARSING_INCOMPLETE
Definition: core_http_client_private.h:213
@ HTTP_PARSING_COMPLETE
Definition: core_http_client_private.h:214
@ HTTP_PARSING_NONE
Definition: core_http_client_private.h:212
The HTTP response parsing context for a response fresh from the server. This context is passed into t...
Definition: core_http_client_private.h:296
const char * pLastHeaderField
Definition: core_http_client_private.h:304
llhttp_t llhttpParser
Definition: core_http_client_private.h:297
size_t lastHeaderValueLen
Definition: core_http_client_private.h:307
HTTPResponse_t * pResponse
Definition: core_http_client_private.h:300
const char * pLastHeaderValue
Definition: core_http_client_private.h:306
size_t lastHeaderFieldLen
Definition: core_http_client_private.h:305
HTTPParsingState_t state
Definition: core_http_client_private.h:299
const char * pBufferCur
Definition: core_http_client_private.h:303
uint8_t isHeadResponse
Definition: core_http_client_private.h:301
llhttp_settings_t llhttpSettings
Definition: core_http_client_private.h:298
Represents an HTTP response.
Definition: core_http_client.h:470
An aggregator that represents the user-provided parameters to the HTTPClient_ReadHeader API function....
Definition: core_http_client_private.h:223
const char ** pValueLoc
Definition: core_http_client_private.h:226
size_t fieldLen
Definition: core_http_client_private.h:225
uint8_t valueFound
Definition: core_http_client_private.h:229
const char * pField
Definition: core_http_client_private.h:224
size_t * pValueLen
Definition: core_http_client_private.h:227
uint8_t fieldFound
Definition: core_http_client_private.h:228