coreHTTP v2.0.0
HTTP/1.1 Client Library
core_http_client_private.h
Go to the documentation of this file.
1/*
2 * coreHTTP v2.0.0
3 * Copyright (C) 2020 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
31/* Third-party http-parser include. */
32#include "http_parser.h"
33
37#define HTTP_PROTOCOL_VERSION "HTTP/1.1"
38#define HTTP_PROTOCOL_VERSION_LEN ( sizeof( HTTP_PROTOCOL_VERSION ) - 1U )
43#define HTTP_EMPTY_PATH "/"
44#define HTTP_EMPTY_PATH_LEN ( sizeof( HTTP_EMPTY_PATH ) - 1U )
46/* Constants for HTTP header formatting. */
47#define HTTP_HEADER_LINE_SEPARATOR "\r\n"
48#define HTTP_HEADER_LINE_SEPARATOR_LEN ( sizeof( HTTP_HEADER_LINE_SEPARATOR ) - 1U )
49#define HTTP_HEADER_END_INDICATOR "\r\n\r\n"
50#define HTTP_HEADER_END_INDICATOR_LEN ( sizeof( HTTP_HEADER_END_INDICATOR ) - 1U )
51#define HTTP_HEADER_FIELD_SEPARATOR ": "
52#define HTTP_HEADER_FIELD_SEPARATOR_LEN ( sizeof( HTTP_HEADER_FIELD_SEPARATOR ) - 1U )
53#define SPACE_CHARACTER ' '
54#define SPACE_CHARACTER_LEN ( 1U )
55#define DASH_CHARACTER '-'
56#define DASH_CHARACTER_LEN ( 1U )
58/* Constants for HTTP header copy checks. */
59#define CARRIAGE_RETURN_CHARACTER '\r'
60#define LINEFEED_CHARACTER '\n'
61#define COLON_CHARACTER ':'
67#define HTTP_HEADER_STRNCPY_IS_VALUE 0U
68
73#define HTTP_HEADER_STRNCPY_IS_FIELD 1U
74
75/* Constants for header fields added automatically during the request
76 * initialization. */
77#define HTTP_USER_AGENT_FIELD "User-Agent"
78#define HTTP_USER_AGENT_FIELD_LEN ( sizeof( HTTP_USER_AGENT_FIELD ) - 1U )
79#define HTTP_HOST_FIELD "Host"
80#define HTTP_HOST_FIELD_LEN ( sizeof( HTTP_HOST_FIELD ) - 1U )
81#define HTTP_USER_AGENT_VALUE_LEN ( sizeof( HTTP_USER_AGENT_VALUE ) - 1U )
83/* Constants for header fields added based on flags. */
84#define HTTP_CONNECTION_FIELD "Connection"
85#define HTTP_CONNECTION_FIELD_LEN ( sizeof( HTTP_CONNECTION_FIELD ) - 1U )
86#define HTTP_CONTENT_LENGTH_FIELD "Content-Length"
87#define HTTP_CONTENT_LENGTH_FIELD_LEN ( sizeof( HTTP_CONTENT_LENGTH_FIELD ) - 1U )
89/* Constants for header values added based on flags. */
90
91/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the
92 * one postfixed with _LEN. This rule is suppressed for naming consistency with
93 * other HTTP header field and value string and length macros in this file.*/
94/* coverity[other_declaration] */
95#define HTTP_CONNECTION_KEEP_ALIVE_VALUE "keep-alive"
97/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one
98 * above it. This rule is suppressed for naming consistency with other HTTP
99 * header field and value string and length macros in this file.*/
100/* coverity[misra_c_2012_rule_5_4_violation] */
101#define HTTP_CONNECTION_KEEP_ALIVE_VALUE_LEN ( sizeof( HTTP_CONNECTION_KEEP_ALIVE_VALUE ) - 1U )
103/* Constants relating to Range Requests. */
104
105/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the
106 * one postfixed with _LEN. This rule is suppressed for naming consistency with
107 * other HTTP header field and value string and length macros in this file.*/
108/* coverity[other_declaration] */
109#define HTTP_RANGE_REQUEST_HEADER_FIELD "Range"
111/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one
112 * above it. This rule is suppressed for naming consistency with other HTTP
113 * header field and value string and length macros in this file.*/
114/* coverity[misra_c_2012_rule_5_4_violation] */
115#define HTTP_RANGE_REQUEST_HEADER_FIELD_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_FIELD ) - 1U )
117/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the
118 * one postfixed with _LEN. This rule is suppressed for naming consistency with
119 * other HTTP header field and value string and length macros in this file.*/
120/* coverity[other_declaration] */
121#define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX "bytes="
123/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one
124 * above it. This rule is suppressed for naming consistency with other HTTP
125 * header field and value string and length macros in this file.*/
126/* coverity[misra_c_2012_rule_5_4_violation] */
127#define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX ) - 1U )
134#define MAX_INT32_NO_OF_DECIMAL_DIGITS 10U
135
142#define HTTP_MAX_RANGE_REQUEST_VALUE_LEN \
143 ( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN + MAX_INT32_NO_OF_DECIMAL_DIGITS + \
144 1U /* Dash character '-' */ + MAX_INT32_NO_OF_DECIMAL_DIGITS )
145
150#define HTTP_PARSER_STOP_PARSING 1
151
156#define HTTP_PARSER_CONTINUE_PARSING 0
157
172#define HTTP_MINIMUM_REQUEST_LINE_LENGTH 16u
173
179{
184
190typedef struct findHeaderContext
191{
192 const char * pField;
193 size_t fieldLen;
194 const char ** pValueLoc;
195 size_t * pValueLen;
196 uint8_t fieldFound;
197 uint8_t valueFound;
199
256typedef struct HTTPParsingContext
257{
258 http_parser httpParser;
263 const char * pBufferCur;
264 const char * pLastHeaderField;
266 const char * pLastHeaderValue;
269
270#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:179
@ HTTP_PARSING_INCOMPLETE
Definition: core_http_client_private.h:181
@ HTTP_PARSING_COMPLETE
Definition: core_http_client_private.h:182
@ HTTP_PARSING_NONE
Definition: core_http_client_private.h:180
The HTTP response parsing context for a response fresh from the server. This context is passed into t...
Definition: core_http_client_private.h:257
http_parser httpParser
Definition: core_http_client_private.h:258
const char * pLastHeaderField
Definition: core_http_client_private.h:264
size_t lastHeaderValueLen
Definition: core_http_client_private.h:267
HTTPResponse_t * pResponse
Definition: core_http_client_private.h:260
const char * pLastHeaderValue
Definition: core_http_client_private.h:266
size_t lastHeaderFieldLen
Definition: core_http_client_private.h:265
HTTPParsingState_t state
Definition: core_http_client_private.h:259
const char * pBufferCur
Definition: core_http_client_private.h:263
uint8_t isHeadResponse
Definition: core_http_client_private.h:261
Represents an HTTP response.
Definition: core_http_client.h:428
An aggregator that represents the user-provided parameters to the HTTPClient_ReadHeader API function....
Definition: core_http_client_private.h:191
const char ** pValueLoc
Definition: core_http_client_private.h:194
size_t fieldLen
Definition: core_http_client_private.h:193
uint8_t valueFound
Definition: core_http_client_private.h:197
const char * pField
Definition: core_http_client_private.h:192
size_t * pValueLen
Definition: core_http_client_private.h:195
uint8_t fieldFound
Definition: core_http_client_private.h:196