Zephyr Project API  3.2.0
A Scalable Open Source RTOS
http_client.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2019 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_HTTP_CLIENT_H_
14#define ZEPHYR_INCLUDE_NET_HTTP_CLIENT_H_
15
23#include <zephyr/kernel.h>
24#include <zephyr/net/net_ip.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#if !defined(HTTP_CRLF)
32#define HTTP_CRLF "\r\n"
33#endif
34
35#if !defined(HTTP_STATUS_STR_SIZE)
36#define HTTP_STATUS_STR_SIZE 32
37#endif
38
39/* Is there more data to come */
43};
44
45struct http_request;
46struct http_response;
47
61typedef int (*http_payload_cb_t)(int sock,
62 struct http_request *req,
63 void *user_data);
64
79typedef int (*http_header_cb_t)(int sock,
80 struct http_request *req,
81 void *user_data);
82
92typedef void (*http_response_cb_t)(struct http_response *rsp,
93 enum http_final_call final_data,
94 void *user_data);
95
102
108
139
142
147
150
161 size_t data_len;
162
167
173 size_t processed;
174
175 /* https://tools.ietf.org/html/rfc7230#section-3.1.2
176 * The status-code element is a 3-digit integer code
177 *
178 * The reason-phrase element exists for the sole
179 * purpose of providing a textual description
180 * associated with the numeric status code. A client
181 * SHOULD ignore the reason-phrase content.
182 *
183 * Will be blank if a null HTTP response is given.
184 */
186
193
197};
198
204
207
210
215
218
220 int sock;
221
224};
225
233
234 /* User should fill in following parameters */
235
238
243
249
252
255
257 const char *url;
258
260 const char *protocol;
261
268 const char **header_fields;
269
272
274 const char *host;
275
277 const char *port;
278
286
288 const char *payload;
289
294
302
312 const char **optional_headers;
313};
314
330int http_client_req(int sock, struct http_request *req,
331 int32_t timeout, void *user_data);
332
333#ifdef __cplusplus
334}
335#endif
336
341#endif /* ZEPHYR_INCLUDE_NET_HTTP_CLIENT_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
http_final_call
Definition: http_client.h:40
#define HTTP_STATUS_STR_SIZE
Definition: http_client.h:36
int(* http_payload_cb_t)(int sock, struct http_request *req, void *user_data)
Callback used when data needs to be sent to the server.
Definition: http_client.h:61
void(* http_response_cb_t)(struct http_response *rsp, enum http_final_call final_data, void *user_data)
Callback used when data is received from the server.
Definition: http_client.h:92
int http_client_req(int sock, struct http_request *req, int32_t timeout, void *user_data)
Do a HTTP request. The callback is called when data is received from the HTTP server....
int(* http_header_cb_t)(int sock, struct http_request *req, void *user_data)
Callback can be used if application wants to construct additional HTTP headers when the HTTP request ...
Definition: http_client.h:79
@ HTTP_DATA_MORE
Definition: http_client.h:41
@ HTTP_DATA_FINAL
Definition: http_client.h:42
http_method
Definition: http_parser.h:92
Public kernel APIs.
IPv6 and IPv4 definitions.
__INT32_TYPE__ int32_t
Definition: stdint.h:74
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Definition: http_client.h:201
struct http_parser parser
Definition: http_client.h:206
struct http_parser_settings parser_settings
Definition: http_client.h:209
void * user_data
Definition: http_client.h:217
struct k_work_delayable work
Definition: http_client.h:203
int sock
Definition: http_client.h:220
struct http_response response
Definition: http_client.h:214
k_timeout_t timeout
Definition: http_client.h:223
Definition: http_parser.h:225
Definition: http_parser.h:182
Definition: http_client.h:230
http_payload_cb_t payload_cb
Definition: http_client.h:285
const char * content_type_value
Definition: http_client.h:271
const char ** header_fields
Definition: http_client.h:268
const char * protocol
Definition: http_client.h:260
const char * host
Definition: http_client.h:274
size_t payload_len
Definition: http_client.h:293
const char * url
Definition: http_client.h:257
size_t recv_buf_len
Definition: http_client.h:254
const char ** optional_headers
Definition: http_client.h:312
http_header_cb_t optional_headers_cb
Definition: http_client.h:301
http_response_cb_t response
Definition: http_client.h:242
uint8_t * recv_buf
Definition: http_client.h:251
struct http_client_internal_data internal
Definition: http_client.h:232
const char * port
Definition: http_client.h:277
enum http_method method
Definition: http_client.h:237
const char * payload
Definition: http_client.h:288
const struct http_parser_settings * http_cb
Definition: http_client.h:248
Definition: http_client.h:99
uint8_t cl_present
Definition: http_client.h:194
size_t processed
Definition: http_client.h:173
http_response_cb_t cb
Definition: http_client.h:107
size_t data_len
Definition: http_client.h:161
uint8_t * body_frag_start
Definition: http_client.h:138
uint8_t message_complete
Definition: http_client.h:196
size_t body_frag_len
Definition: http_client.h:141
size_t recv_buf_len
Definition: http_client.h:149
uint16_t http_status_code
Definition: http_client.h:192
uint8_t * recv_buf
Definition: http_client.h:146
uint8_t body_found
Definition: http_client.h:195
char http_status[32]
Definition: http_client.h:185
size_t content_length
Definition: http_client.h:166
const struct http_parser_settings * http_cb
Definition: http_client.h:101
Kernel timeout type.
Definition: sys_clock.h:65
A structure used to submit work after a delay.
Definition: kernel.h:3692
static const intptr_t user_data[5]
Definition: main.c:588