Zephyr Project API  3.1.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
172 size_t processed;
173
174 /* https://tools.ietf.org/html/rfc7230#section-3.1.2
175 * The status-code element is a 3-digit integer code
176 *
177 * The reason-phrase element exists for the sole
178 * purpose of providing a textual description
179 * associated with the numeric status code. A client
180 * SHOULD ignore the reason-phrase content.
181 *
182 * Will be blank if a null HTTP response is given.
183 */
185
192
196};
197
203
206
209
214
217
219 int sock;
220
223};
224
232
233 /* User should fill in following parameters */
234
237
242
248
251
254
256 const char *url;
257
259 const char *protocol;
260
267 const char **header_fields;
268
271
273 const char *host;
274
276 const char *port;
277
285
287 const char *payload;
288
293
301
311 const char **optional_headers;
312};
313
329int http_client_req(int sock, struct http_request *req,
330 int32_t timeout, void *user_data);
331
332#ifdef __cplusplus
333}
334#endif
335
340#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:200
struct http_parser parser
Definition: http_client.h:205
struct http_parser_settings parser_settings
Definition: http_client.h:208
void * user_data
Definition: http_client.h:216
struct k_work_delayable work
Definition: http_client.h:202
int sock
Definition: http_client.h:219
struct http_response response
Definition: http_client.h:213
k_timeout_t timeout
Definition: http_client.h:222
Definition: http_parser.h:225
Definition: http_parser.h:182
Definition: http_client.h:229
http_payload_cb_t payload_cb
Definition: http_client.h:284
const char * content_type_value
Definition: http_client.h:270
const char ** header_fields
Definition: http_client.h:267
const char * protocol
Definition: http_client.h:259
const char * host
Definition: http_client.h:273
size_t payload_len
Definition: http_client.h:292
const char * url
Definition: http_client.h:256
size_t recv_buf_len
Definition: http_client.h:253
const char ** optional_headers
Definition: http_client.h:311
http_header_cb_t optional_headers_cb
Definition: http_client.h:300
http_response_cb_t response
Definition: http_client.h:241
uint8_t * recv_buf
Definition: http_client.h:250
struct http_client_internal_data internal
Definition: http_client.h:231
const char * port
Definition: http_client.h:276
enum http_method method
Definition: http_client.h:236
const char * payload
Definition: http_client.h:287
const struct http_parser_settings * http_cb
Definition: http_client.h:247
Definition: http_client.h:99
uint8_t cl_present
Definition: http_client.h:193
size_t processed
Definition: http_client.h:172
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:195
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:191
uint8_t * recv_buf
Definition: http_client.h:146
uint8_t body_found
Definition: http_client.h:194
char http_status[32]
Definition: http_client.h:184
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:3670
static const intptr_t user_data[5]
Definition: main.c:590