Zephyr API Documentation  2.7.0-rc2
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 <kernel.h>
24#include <net/net_ip.h>
25#include <net/http_parser.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
111
116
119
129 size_t data_len;
130
133
137 size_t processed;
138
139 /* https://tools.ietf.org/html/rfc7230#section-3.1.2
140 * The status-code element is a 3-digit integer code
141 *
142 * The reason-phrase element exists for the sole
143 * purpose of providing a textual description
144 * associated with the numeric status code. A client
145 * SHOULD ignore the reason-phrase content.
146 */
148
153
157};
158
164
167
170
175
178
180 int sock;
181
184};
185
193
194 /* User should fill in following parameters */
195
198
203
209
212
215
217 const char *url;
218
220 const char *protocol;
221
228 const char **header_fields;
229
232
234 const char *host;
235
237 const char *port;
238
246
248 const char *payload;
249
254
262
272 const char **optional_headers;
273};
274
290int http_client_req(int sock, struct http_request *req,
291 int32_t timeout, void *user_data);
292
293#ifdef __cplusplus
294}
295#endif
296
301#endif /* ZEPHYR_INCLUDE_NET_HTTP_CLIENT_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
void
Definition: eswifi_shell.c:15
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
IPv6 and IPv4 definitions.
__INT32_TYPE__ int32_t
Definition: stdint.h:44
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Definition: http_client.h:161
struct http_parser parser
Definition: http_client.h:166
struct http_parser_settings parser_settings
Definition: http_client.h:169
void * user_data
Definition: http_client.h:177
struct k_work_delayable work
Definition: http_client.h:163
int sock
Definition: http_client.h:180
struct http_response response
Definition: http_client.h:174
k_timeout_t timeout
Definition: http_client.h:183
Definition: http_parser.h:225
Definition: http_parser.h:182
Definition: http_client.h:190
http_payload_cb_t payload_cb
Definition: http_client.h:245
const char * content_type_value
Definition: http_client.h:231
const char ** header_fields
Definition: http_client.h:228
const char * protocol
Definition: http_client.h:220
const char * host
Definition: http_client.h:234
size_t payload_len
Definition: http_client.h:253
const char * url
Definition: http_client.h:217
size_t recv_buf_len
Definition: http_client.h:214
const char ** optional_headers
Definition: http_client.h:272
http_header_cb_t optional_headers_cb
Definition: http_client.h:261
http_response_cb_t response
Definition: http_client.h:202
uint8_t * recv_buf
Definition: http_client.h:211
struct http_client_internal_data internal
Definition: http_client.h:192
const char * port
Definition: http_client.h:237
enum http_method method
Definition: http_client.h:197
const char * payload
Definition: http_client.h:248
const struct http_parser_settings * http_cb
Definition: http_client.h:208
Definition: http_client.h:99
uint8_t cl_present
Definition: http_client.h:154
size_t processed
Definition: http_client.h:137
http_response_cb_t cb
Definition: http_client.h:107
size_t data_len
Definition: http_client.h:129
uint8_t message_complete
Definition: http_client.h:156
size_t recv_buf_len
Definition: http_client.h:118
uint16_t http_status_code
Definition: http_client.h:152
uint8_t * recv_buf
Definition: http_client.h:115
uint8_t * body_start
Definition: http_client.h:110
uint8_t body_found
Definition: http_client.h:155
char http_status[32]
Definition: http_client.h:147
size_t content_length
Definition: http_client.h:132
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:3651
static const intptr_t user_data[5]
Definition: main.c:590