Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
25#include <zephyr/kernel.h>
26#include <zephyr/net/net_ip.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
35#if !defined(HTTP_CRLF)
36#define HTTP_CRLF "\r\n"
37#endif
38
39#if !defined(HTTP_STATUS_STR_SIZE)
40#define HTTP_STATUS_STR_SIZE 32
41#endif
42
49};
50
51struct http_request;
52struct http_response;
53
67typedef int (*http_payload_cb_t)(int sock,
68 struct http_request *req,
69 void *user_data);
70
85typedef int (*http_header_cb_t)(int sock,
86 struct http_request *req,
87 void *user_data);
88
98typedef void (*http_response_cb_t)(struct http_response *rsp,
99 enum http_final_call final_data,
100 void *user_data);
101
108
114
145
148
153
156
167 size_t data_len;
168
173
179 size_t processed;
180
191 char http_status[HTTP_STATUS_STR_SIZE];
192
199
203};
204
210
213
218
221
223 int sock;
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_ */
http_final_call
Is there more data to come.
Definition: client.h:46
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:67
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:98
int http_client_req(int sock, struct http_request *req, int32_t timeout, void *user_data)
Do a HTTP request.
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:85
@ HTTP_DATA_MORE
More data will come.
Definition: client.h:47
@ HTTP_DATA_FINAL
End of data.
Definition: client.h:48
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
HTTP client internal data that the application should not touch.
Definition: client.h:207
struct http_parser parser
HTTP parser context.
Definition: client.h:209
struct http_parser_settings parser_settings
HTTP parser settings.
Definition: client.h:212
void * user_data
User data.
Definition: client.h:220
int sock
HTTP socket.
Definition: client.h:223
struct http_response response
HTTP response specific data (filled by http_client_req() when data is received)
Definition: client.h:217
Definition: parser.h:190
Definition: parser.h:147
HTTP client request.
Definition: client.h:230
http_payload_cb_t payload_cb
User supplied callback function to call when payload needs to be sent.
Definition: client.h:285
const char * content_type_value
The value of the Content-Type header field, may be NULL.
Definition: client.h:271
const char ** header_fields
The HTTP header fields (application specific) The Content-Type may be specified here or in the next f...
Definition: client.h:268
const char * protocol
The HTTP protocol, for example "HTTP/1.1".
Definition: client.h:260
const char * host
Hostname to be used in the request.
Definition: client.h:274
size_t payload_len
Payload length is used to calculate Content-Length.
Definition: client.h:293
const char * url
The URL for this request, for example: /index.html.
Definition: client.h:257
size_t recv_buf_len
Length of the user supplied receive buffer.
Definition: client.h:254
const char ** optional_headers
A NULL terminated list of any optional headers that should be added to the HTTP request.
Definition: client.h:312
http_header_cb_t optional_headers_cb
User supplied callback function to call when optional headers need to be sent.
Definition: client.h:301
http_response_cb_t response
User supplied callback function to call when response is received.
Definition: client.h:242
uint8_t * recv_buf
User supplied buffer where received data is stored.
Definition: client.h:251
struct http_client_internal_data internal
HTTP client request internal data.
Definition: client.h:232
const char * port
Port number to be used in the request.
Definition: client.h:277
enum http_method method
The HTTP method: GET, HEAD, OPTIONS, POST, ...
Definition: client.h:237
const char * payload
Payload, may be NULL.
Definition: client.h:288
const struct http_parser_settings * http_cb
User supplied list of HTTP callback functions if the calling application wants to know the parsing st...
Definition: client.h:248
HTTP response from the server.
Definition: client.h:105
uint8_t cl_present
Is Content-Length field present.
Definition: client.h:200
size_t processed
Amount of data given to the response callback so far, including the current data given to the callbac...
Definition: client.h:179
http_response_cb_t cb
User provided HTTP response callback which is called when a response is received to a sent HTTP reque...
Definition: client.h:113
size_t data_len
Length of the data in the result buf.
Definition: client.h:167
uint8_t * body_frag_start
Start address of the body fragment contained in the recv_buf.
Definition: client.h:144
uint8_t message_complete
Is HTTP message parsing complete.
Definition: client.h:202
size_t body_frag_len
Length of the body fragment contained in the recv_buf.
Definition: client.h:147
size_t recv_buf_len
Response buffer maximum length.
Definition: client.h:155
uint16_t http_status_code
Numeric HTTP status code which corresponds to the textual description.
Definition: client.h:198
uint8_t * recv_buf
Where the response is stored, this is to be provided by the user.
Definition: client.h:152
uint8_t body_found
Is message body found.
Definition: client.h:201
size_t content_length
HTTP Content-Length field value.
Definition: client.h:172
const struct http_parser_settings * http_cb
HTTP parser settings for the application usage.
Definition: client.h:107