-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathcore_http_client_private.h
More file actions
224 lines (204 loc) · 7.5 KB
/
core_http_client_private.h
File metadata and controls
224 lines (204 loc) · 7.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* coreHTTP v2.1.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file core_http_client_private.h
* @brief Internal definitions to the HTTP Client library.
*/
#ifndef CORE_HTTP_CLIENT_PRIVATE_H_
#define CORE_HTTP_CLIENT_PRIVATE_H_
/**
* @cond DOXYGEN_IGNORE
* http-parser defaults this to 1, llhttp to 0.
*/
#ifndef LLHTTP_STRICT_MODE
#define LLHTTP_STRICT_MODE 0
#endif
/** @endcond */
/* Third-party llhttp include. */
#include "llhttp.h"
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/**
* @brief Indicator for function #httpHeaderStrncpy that the pSrc parameter is a
* header value.
*/
#define HTTP_HEADER_STRNCPY_IS_VALUE 0U
/**
* @brief Indicator for function #httpHeaderStrncpy that the pSrc parameter is a
* header field.
*/
#define HTTP_HEADER_STRNCPY_IS_FIELD 1U
/**
* @brief Maximum value of a 32 bit signed integer is 2,147,483,647.
*
* Used for calculating buffer space for ASCII representation of range values.
*/
#define MAX_INT32_NO_OF_DECIMAL_DIGITS 10U
/**
* @brief Maximum buffer space for storing a Range Request Value.
*
* The largest Range Request value is of the form:
* "bytes=<Max-Integer-Value>-<Max-Integer-Value>"
*/
#define HTTP_MAX_RANGE_REQUEST_VALUE_LEN \
( sizeof( "bytes=" ) - 1U + MAX_INT32_NO_OF_DECIMAL_DIGITS + \
1U + MAX_INT32_NO_OF_DECIMAL_DIGITS )
/**
* @brief Return value for llhttp registered callback to signal
* continuation of HTTP response parsing. Equal to HPE_OK.
*/
#define LLHTTP_CONTINUE_PARSING 0
/**
* @brief Return value for llhttp registered callback to signal halting
* further execution.
*/
#define LLHTTP_STOP_PARSING HPE_USER
/**
* @brief Return value for llhttp_t.on_headers_complete to signal
* that the HTTP response has no body and to halt further execution.
*/
#define LLHTTP_STOP_PARSING_NO_BODY 1
/**
* @brief Return value for llhttp_t.on_headers_complete to signal
* halting further execution. This is the same return value that
* indicates the HTTP response has no body, but unlike the -1 error
* code, gives consistent return values for llhttp_execute in both
* strict and non-strict modes.
*/
#define LLHTTP_STOP_PARSING_NO_HEADER 1
/**
* @brief The minimum request-line in the headers has a possible one character
* custom method and a single forward / or asterisk * for the path:
*
* @code
* <1 character custom method> <1 character / or *> HTTP/1.x\r\n\r\n
* @endcode
*
* Therefore the minimum length is 16. If this minimum request-line is not
* satisfied, then the request headers to send are invalid.
*
* Note that custom methods are allowed per:
* https://tools.ietf.org/html/rfc2616#section-5.1.1.
*/
#define HTTP_MINIMUM_REQUEST_LINE_LENGTH 16u
/**
* @brief The state of the response message parsed after function
* #parseHttpResponse returns.
*/
typedef enum HTTPParsingState_t
{
HTTP_PARSING_NONE = 0, /**< The parser has not started reading any response. */
HTTP_PARSING_INCOMPLETE, /**< The parser found a partial reponse. */
HTTP_PARSING_COMPLETE /**< The parser found the entire response. */
} HTTPParsingState_t;
/**
* @brief An aggregator that represents the user-provided parameters to the
* #HTTPClient_ReadHeader API function. This will be used as context parameter
* for the parsing callbacks used by the API function.
*/
typedef struct findHeaderContext
{
const char * pField; /**< The field that is being searched for. */
size_t fieldLen; /**< The length of pField. */
const char ** pValueLoc; /**< The location of the value found in the buffer. */
size_t * pValueLen; /**< the length of the value found. */
uint8_t fieldFound; /**< Indicates that the header field was found during parsing. */
uint8_t valueFound; /**< Indicates that the header value was found during parsing. */
} findHeaderContext_t;
/**
* @brief The HTTP response parsing context for a response fresh from the
* server. This context is passed into the http-parser registered callbacks.
* The registered callbacks are private functions of the form
* httpParserXXXXCallbacks().
*
* The transitions of the httpParserXXXXCallback() functions are shown below.
* The XXXX is replaced by the strings in the state boxes:
*
* +---------------------+
* |onMessageBegin |
* +--------+------------+
* |
* |
* |
* v
* +--------+------------+
* |onStatus |
* +--------+------------+
* |
* |
* |
* v
* +--------+------------+
* |onHeaderField +<---+
* +--------+------------+ |
* | |
* | |(More headers)
* | |
* v |
* +--------+------------+ |
* |onHeaderValue +----^
* +--------+------------+
* |
* |
* |
* v
* +--------+------------+
* |onHeadersComplete |
* +---------------------+
* |
* |
* |
* v
* +--------+------------+
* |onBody +<---+
* +--------+--------+---+ |
* | | |(Transfer-encoding chunked body)
* | | |
* | +--------+
* |
* v
* +--------+------------+
* |onMessageComplete |
* +---------------------+
*/
typedef struct HTTPParsingContext
{
llhttp_t llhttpParser; /**< Third-party llhttp context. */
llhttp_settings_t llhttpSettings; /**< Third-party parser settings. */
HTTPParsingState_t state; /**< The current state of the HTTP response parsed. */
HTTPResponse_t * pResponse; /**< HTTP response associated with this parsing context. */
uint8_t isHeadResponse; /**< HTTP response is for a HEAD request. */
const char * pBufferCur; /**< The current location of the parser in the response buffer. */
const char * pLastHeaderField; /**< Holds the last part of the header field parsed. */
size_t lastHeaderFieldLen; /**< The length of the last header field parsed. */
const char * pLastHeaderValue; /**< Holds the last part of the header value parsed. */
size_t lastHeaderValueLen; /**< The length of the last value field parsed. */
} HTTPParsingContext_t;
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* ifndef CORE_HTTP_CLIENT_PRIVATE_H_ */