Zephyr Project API  3.3.0
A Scalable Open Source RTOS
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
212
215
217 int sock;
218};
219
227
228 /* User should fill in following parameters */
229
232
237
243
246
249
251 const char *url;
252
254 const char *protocol;
255
262 const char **header_fields;
263
266
268 const char *host;
269
271 const char *port;
272
280
282 const char *payload;
283
288
296
306 const char **optional_headers;
307};
308
324int http_client_req(int sock, struct http_request *req,
325 int32_t timeout, void *user_data);
326
327#ifdef __cplusplus
328}
329#endif
330
335#endif /* ZEPHYR_INCLUDE_NET_HTTP_CLIENT_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
http_final_call
Definition: client.h:40
#define HTTP_STATUS_STR_SIZE
Definition: 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: 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: 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: client.h:79
@ HTTP_DATA_MORE
Definition: client.h:41
@ HTTP_DATA_FINAL
Definition: client.h:42
http_method
HTTP Request Methods.
Definition: method.h:26
http_status
HTTP response status codes.
Definition: status.h:34
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: client.h:201
struct http_parser parser
Definition: client.h:203
struct http_parser_settings parser_settings
Definition: client.h:206
void * user_data
Definition: client.h:214
int sock
Definition: client.h:217
struct http_response response
Definition: client.h:211
Definition: parser.h:190
Definition: parser.h:147
Definition: client.h:224
http_payload_cb_t payload_cb
Definition: client.h:279
const char * content_type_value
Definition: client.h:265
const char ** header_fields
Definition: client.h:262
const char * protocol
Definition: client.h:254
const char * host
Definition: client.h:268
size_t payload_len
Definition: client.h:287
const char * url
Definition: client.h:251
size_t recv_buf_len
Definition: client.h:248
const char ** optional_headers
Definition: client.h:306
http_header_cb_t optional_headers_cb
Definition: client.h:295
http_response_cb_t response
Definition: client.h:236
uint8_t * recv_buf
Definition: client.h:245
struct http_client_internal_data internal
Definition: client.h:226
const char * port
Definition: client.h:271
enum http_method method
Definition: client.h:231
const char * payload
Definition: client.h:282
const struct http_parser_settings * http_cb
Definition: client.h:242
Definition: client.h:99
uint8_t cl_present
Definition: client.h:194
size_t processed
Definition: client.h:173
http_response_cb_t cb
Definition: client.h:107
size_t data_len
Definition: client.h:161
uint8_t * body_frag_start
Definition: client.h:138
uint8_t message_complete
Definition: client.h:196
size_t body_frag_len
Definition: client.h:141
size_t recv_buf_len
Definition: client.h:149
uint16_t http_status_code
Definition: client.h:192
uint8_t * recv_buf
Definition: client.h:146
uint8_t body_found
Definition: client.h:195
size_t content_length
Definition: client.h:166
const struct http_parser_settings * http_cb
Definition: client.h:101
static const intptr_t user_data[5]
Definition: main.c:588