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
33#if !defined(HTTP_CRLF)
34#define HTTP_CRLF "\r\n"
35#endif
36
37#if !defined(HTTP_STATUS_STR_SIZE)
38#define HTTP_STATUS_STR_SIZE 32
39#endif
40
41/* Is there more data to come */
45};
46
47struct http_request;
48struct http_response;
49
63typedef int (*http_payload_cb_t)(int sock,
64 struct http_request *req,
65 void *user_data);
66
81typedef int (*http_header_cb_t)(int sock,
82 struct http_request *req,
83 void *user_data);
84
94typedef void (*http_response_cb_t)(struct http_response *rsp,
95 enum http_final_call final_data,
96 void *user_data);
97
104
110
141
144
149
152
163 size_t data_len;
164
169
175 size_t processed;
176
177 /* https://tools.ietf.org/html/rfc7230#section-3.1.2
178 * The status-code element is a 3-digit integer code
179 *
180 * The reason-phrase element exists for the sole
181 * purpose of providing a textual description
182 * associated with the numeric status code. A client
183 * SHOULD ignore the reason-phrase content.
184 *
185 * Will be blank if a null HTTP response is given.
186 */
188
195
199};
200
206
209
214
217
219 int sock;
220};
221
229
230 /* User should fill in following parameters */
231
234
239
245
248
251
253 const char *url;
254
256 const char *protocol;
257
264 const char **header_fields;
265
268
270 const char *host;
271
273 const char *port;
274
282
284 const char *payload;
285
290
298
308 const char **optional_headers;
309};
310
326int http_client_req(int sock, struct http_request *req,
327 int32_t timeout, void *user_data);
328
329#ifdef __cplusplus
330}
331#endif
332
337#endif /* ZEPHYR_INCLUDE_NET_HTTP_CLIENT_H_ */
http_final_call
Definition: client.h:42
#define HTTP_STATUS_STR_SIZE
Definition: client.h:38
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:63
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:94
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:81
@ HTTP_DATA_MORE
Definition: client.h:43
@ HTTP_DATA_FINAL
Definition: client.h:44
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:203
struct http_parser parser
HTTP parser context.
Definition: client.h:205
struct http_parser_settings parser_settings
HTTP parser settings.
Definition: client.h:208
void * user_data
User data.
Definition: client.h:216
int sock
HTTP socket.
Definition: client.h:219
struct http_response response
HTTP response specific data (filled by http_client_req() when data is received)
Definition: client.h:213
Definition: parser.h:190
Definition: parser.h:147
HTTP client request.
Definition: client.h:226
http_payload_cb_t payload_cb
User supplied callback function to call when payload needs to be sent.
Definition: client.h:281
const char * content_type_value
The value of the Content-Type header field, may be NULL.
Definition: client.h:267
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:264
const char * protocol
The HTTP protocol, for example "HTTP/1.1".
Definition: client.h:256
const char * host
Hostname to be used in the request.
Definition: client.h:270
size_t payload_len
Payload length is used to calculate Content-Length.
Definition: client.h:289
const char * url
The URL for this request, for example: /index.html.
Definition: client.h:253
size_t recv_buf_len
Length of the user supplied receive buffer.
Definition: client.h:250
const char ** optional_headers
A NULL terminated list of any optional headers that should be added to the HTTP request.
Definition: client.h:308
http_header_cb_t optional_headers_cb
User supplied callback function to call when optional headers need to be sent.
Definition: client.h:297
http_response_cb_t response
User supplied callback function to call when response is received.
Definition: client.h:238
uint8_t * recv_buf
User supplied buffer where received data is stored.
Definition: client.h:247
struct http_client_internal_data internal
HTTP client request internal data.
Definition: client.h:228
const char * port
Port number to be used in the request.
Definition: client.h:273
enum http_method method
The HTTP method: GET, HEAD, OPTIONS, POST, ...
Definition: client.h:233
const char * payload
Payload, may be NULL.
Definition: client.h:284
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:244
HTTP response from the server.
Definition: client.h:101
uint8_t cl_present
Definition: client.h:196
size_t processed
Amount of data given to the response callback so far, including the current data given to the callbac...
Definition: client.h:175
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:109
size_t data_len
Length of the data in the result buf.
Definition: client.h:163
uint8_t * body_frag_start
Start address of the body fragment contained in the recv_buf.
Definition: client.h:140
uint8_t message_complete
Definition: client.h:198
size_t body_frag_len
Length of the body fragment contained in the recv_buf.
Definition: client.h:143
size_t recv_buf_len
Response buffer maximum length.
Definition: client.h:151
uint16_t http_status_code
Numeric HTTP status code which corresponds to the textual description.
Definition: client.h:194
uint8_t * recv_buf
Where the response is stored, this is to be provided by the user.
Definition: client.h:148
uint8_t body_found
Definition: client.h:197
size_t content_length
HTTP Content-Length field value.
Definition: client.h:168
const struct http_parser_settings * http_cb
HTTP parser settings for the application usage.
Definition: client.h:103