coreHTTP v3.0.0
HTTP/1.1 Client Library
core_http_client_private.h
Go to the documentation of this file.
1/*
2 * coreHTTP v3.0.0
3 * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
28#ifndef CORE_HTTP_CLIENT_PRIVATE_H_
29#define CORE_HTTP_CLIENT_PRIVATE_H_
30
35#ifndef LLHTTP_STRICT_MODE
36 #define LLHTTP_STRICT_MODE 0
37#endif
40/* Third-party llhttp include. */
41#include "llhttp.h"
42
43/* *INDENT-OFF* */
44#ifdef __cplusplus
45 extern "C" {
46#endif
47/* *INDENT-ON* */
48
52#define HTTP_PROTOCOL_VERSION "HTTP/1.1"
53#define HTTP_PROTOCOL_VERSION_LEN ( sizeof( HTTP_PROTOCOL_VERSION ) - 1U )
58#define HTTP_EMPTY_PATH "/"
59#define HTTP_EMPTY_PATH_LEN ( sizeof( HTTP_EMPTY_PATH ) - 1U )
61/* Constants for HTTP header formatting. */
62#define HTTP_HEADER_LINE_SEPARATOR "\r\n"
63#define HTTP_HEADER_LINE_SEPARATOR_LEN ( sizeof( HTTP_HEADER_LINE_SEPARATOR ) - 1U )
64#define HTTP_HEADER_END_INDICATOR "\r\n\r\n"
65#define HTTP_HEADER_END_INDICATOR_LEN ( sizeof( HTTP_HEADER_END_INDICATOR ) - 1U )
66#define HTTP_HEADER_FIELD_SEPARATOR ": "
67#define HTTP_HEADER_FIELD_SEPARATOR_LEN ( sizeof( HTTP_HEADER_FIELD_SEPARATOR ) - 1U )
68#define SPACE_CHARACTER ' '
69#define SPACE_CHARACTER_LEN ( 1U )
70#define DASH_CHARACTER '-'
71#define DASH_CHARACTER_LEN ( 1U )
73/* Constants for HTTP header copy checks. */
74#define CARRIAGE_RETURN_CHARACTER '\r'
75#define LINEFEED_CHARACTER '\n'
76#define COLON_CHARACTER ':'
82#define HTTP_HEADER_STRNCPY_IS_VALUE 0U
83
88#define HTTP_HEADER_STRNCPY_IS_FIELD 1U
89
90/* Constants for header fields added automatically during the request
91 * initialization. */
92#define HTTP_USER_AGENT_FIELD "User-Agent"
93#define HTTP_USER_AGENT_FIELD_LEN ( sizeof( HTTP_USER_AGENT_FIELD ) - 1U )
94#define HTTP_HOST_FIELD "Host"
95#define HTTP_HOST_FIELD_LEN ( sizeof( HTTP_HOST_FIELD ) - 1U )
96#define HTTP_USER_AGENT_VALUE_LEN ( sizeof( HTTP_USER_AGENT_VALUE ) - 1U )
98/* Constants for header fields added based on flags. */
99#define HTTP_CONNECTION_FIELD "Connection"
100#define HTTP_CONNECTION_FIELD_LEN ( sizeof( HTTP_CONNECTION_FIELD ) - 1U )
101#define HTTP_CONTENT_LENGTH_FIELD "Content-Length"
102#define HTTP_CONTENT_LENGTH_FIELD_LEN ( sizeof( HTTP_CONTENT_LENGTH_FIELD ) - 1U )
104/* Constants for header values added based on flags. */
105
106/* MISRA Ref 5.4.1 [Macro identifiers] */
107/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
108/* coverity[other_declaration] */
109#define HTTP_CONNECTION_KEEP_ALIVE_VALUE "keep-alive"
111/* MISRA Ref 5.4.2 [Macro identifiers] */
112/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
113/* coverity[misra_c_2012_rule_5_4_violation] */
114#define HTTP_CONNECTION_KEEP_ALIVE_VALUE_LEN ( sizeof( HTTP_CONNECTION_KEEP_ALIVE_VALUE ) - 1U )
116/* Constants relating to Range Requests. */
117
118/* MISRA Ref 5.4.3 [Macro identifiers] */
119/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
120/* coverity[other_declaration] */
121#define HTTP_RANGE_REQUEST_HEADER_FIELD "Range"
123/* MISRA Ref 5.4.4 [Macro identifiers] */
124/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
125/* coverity[misra_c_2012_rule_5_4_violation] */
126#define HTTP_RANGE_REQUEST_HEADER_FIELD_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_FIELD ) - 1U )
128/* MISRA Ref 5.4.5 [Macro identifiers] */
129/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
130/* coverity[other_declaration] */
131#define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX "bytes="
133/* MISRA Ref 5.4.6 [Macro identifiers] */
134/* More details at: https://github.com/FreeRTOS/coreHTTP/blob/main/MISRA.md#rule-54 */
135/* coverity[misra_c_2012_rule_5_4_violation] */
136#define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX ) - 1U )
143#define MAX_INT32_NO_OF_DECIMAL_DIGITS 10U
144
151#define HTTP_MAX_RANGE_REQUEST_VALUE_LEN \
152 ( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN + MAX_INT32_NO_OF_DECIMAL_DIGITS + \
153 1U /* Dash character '-' */ + MAX_INT32_NO_OF_DECIMAL_DIGITS )
154
159#define LLHTTP_CONTINUE_PARSING 0
160
165#define LLHTTP_STOP_PARSING HPE_USER
166
171#define LLHTTP_STOP_PARSING_NO_BODY 1
172
180#define LLHTTP_STOP_PARSING_NO_HEADER 1
181
196#define HTTP_MINIMUM_REQUEST_LINE_LENGTH 16u
197
203{
208
214typedef struct findHeaderContext
215{
216 const char * pField;
217 size_t fieldLen;
218 const char ** pValueLoc;
219 size_t * pValueLen;
220 uint8_t fieldFound;
221 uint8_t valueFound;
223
280typedef struct HTTPParsingContext
281{
282 llhttp_t llhttpParser;
283 llhttp_settings_t llhttpSettings;
288 const char * pBufferCur;
289 const char * pLastHeaderField;
291 const char * pLastHeaderValue;
294
295/* *INDENT-OFF* */
296#ifdef __cplusplus
297 }
298#endif
299/* *INDENT-ON* */
300
301#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:203
@ HTTP_PARSING_INCOMPLETE
Definition: core_http_client_private.h:205
@ HTTP_PARSING_COMPLETE
Definition: core_http_client_private.h:206
@ HTTP_PARSING_NONE
Definition: core_http_client_private.h:204
The HTTP response parsing context for a response fresh from the server. This context is passed into t...
Definition: core_http_client_private.h:281
const char * pLastHeaderField
Definition: core_http_client_private.h:289
llhttp_t llhttpParser
Definition: core_http_client_private.h:282
size_t lastHeaderValueLen
Definition: core_http_client_private.h:292
HTTPResponse_t * pResponse
Definition: core_http_client_private.h:285
const char * pLastHeaderValue
Definition: core_http_client_private.h:291
size_t lastHeaderFieldLen
Definition: core_http_client_private.h:290
HTTPParsingState_t state
Definition: core_http_client_private.h:284
const char * pBufferCur
Definition: core_http_client_private.h:288
uint8_t isHeadResponse
Definition: core_http_client_private.h:286
llhttp_settings_t llhttpSettings
Definition: core_http_client_private.h:283
Represents an HTTP response.
Definition: core_http_client.h:425
An aggregator that represents the user-provided parameters to the HTTPClient_ReadHeader API function....
Definition: core_http_client_private.h:215
const char ** pValueLoc
Definition: core_http_client_private.h:218
size_t fieldLen
Definition: core_http_client_private.h:217
uint8_t valueFound
Definition: core_http_client_private.h:221
const char * pField
Definition: core_http_client_private.h:216
size_t * pValueLen
Definition: core_http_client_private.h:219
uint8_t fieldFound
Definition: core_http_client_private.h:220