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 * 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_STOP_PARSING_NO_BODY 1
174
182#define LLHTTP_STOP_PARSING_NO_HEADER 1
183
198#define HTTP_MINIMUM_REQUEST_LINE_LENGTH 16u
199
205{
210
216typedef struct findHeaderContext
217{
218 const char * pField;
219 size_t fieldLen;
220 const char ** pValueLoc;
221 size_t * pValueLen;
222 uint8_t fieldFound;
223 uint8_t valueFound;
225
282typedef struct HTTPParsingContext
283{
284 llhttp_t llhttpParser;
285 llhttp_settings_t llhttpSettings;
290 const char * pBufferCur;
291 const char * pLastHeaderField;
293 const char * pLastHeaderValue;
296
297/* *INDENT-OFF* */
298#ifdef __cplusplus
299 }
300#endif
301/* *INDENT-ON* */
302
303#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:205
@ HTTP_PARSING_INCOMPLETE
Definition: core_http_client_private.h:207
@ HTTP_PARSING_COMPLETE
Definition: core_http_client_private.h:208
@ HTTP_PARSING_NONE
Definition: core_http_client_private.h:206
The HTTP response parsing context for a response fresh from the server. This context is passed into t...
Definition: core_http_client_private.h:283
const char * pLastHeaderField
Definition: core_http_client_private.h:291
llhttp_t llhttpParser
Definition: core_http_client_private.h:284
size_t lastHeaderValueLen
Definition: core_http_client_private.h:294
HTTPResponse_t * pResponse
Definition: core_http_client_private.h:287
const char * pLastHeaderValue
Definition: core_http_client_private.h:293
size_t lastHeaderFieldLen
Definition: core_http_client_private.h:292
HTTPParsingState_t state
Definition: core_http_client_private.h:286
const char * pBufferCur
Definition: core_http_client_private.h:290
uint8_t isHeadResponse
Definition: core_http_client_private.h:288
llhttp_settings_t llhttpSettings
Definition: core_http_client_private.h:285
Represents an HTTP response.
Definition: core_http_client.h:427
An aggregator that represents the user-provided parameters to the HTTPClient_ReadHeader API function....
Definition: core_http_client_private.h:217
const char ** pValueLoc
Definition: core_http_client_private.h:220
size_t fieldLen
Definition: core_http_client_private.h:219
uint8_t valueFound
Definition: core_http_client_private.h:223
const char * pField
Definition: core_http_client_private.h:218
size_t * pValueLen
Definition: core_http_client_private.h:221
uint8_t fieldFound
Definition: core_http_client_private.h:222