Zephyr API Documentation 4.0.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
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
211
232
240
241 /* User should fill in following parameters */
242
245
250
256
259
262
264 const char *url;
265
267 const char *protocol;
268
275 const char **header_fields;
276
279
281 const char *host;
282
284 const char *port;
285
293
295 const char *payload;
296
301
309
319 const char **optional_headers;
320};
321
337int http_client_req(int sock, struct http_request *req,
338 int32_t timeout, void *user_data);
339
340#ifdef __cplusplus
341}
342#endif
343
348#endif /* ZEPHYR_INCLUDE_NET_HTTP_CLIENT_H_ */
http_final_call
Is there more data to come.
Definition client.h:46
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
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_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
@ 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:28
http_status
HTTP response status codes.
Definition status.h:36
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:214
struct http_parser parser
HTTP parser context.
Definition client.h:216
struct http_parser_settings parser_settings
HTTP parser settings.
Definition client.h:219
void * user_data
User data.
Definition client.h:227
int sock
HTTP socket.
Definition client.h:230
struct http_response response
HTTP response specific data (filled by http_client_req() when data is received)
Definition client.h:224
Definition parser.h:149
Definition parser.h:200
Definition parser.h:155
HTTP client request.
Definition client.h:237
http_payload_cb_t payload_cb
User supplied callback function to call when payload needs to be sent.
Definition client.h:292
const char * content_type_value
The value of the Content-Type header field, may be NULL.
Definition client.h:278
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:275
const char * protocol
The HTTP protocol, for example "HTTP/1.1".
Definition client.h:267
const char * host
Hostname to be used in the request.
Definition client.h:281
size_t payload_len
Payload length is used to calculate Content-Length.
Definition client.h:300
const char * url
The URL for this request, for example: /index.html.
Definition client.h:264
size_t recv_buf_len
Length of the user supplied receive buffer.
Definition client.h:261
const char ** optional_headers
A NULL terminated list of any optional headers that should be added to the HTTP request.
Definition client.h:319
http_header_cb_t optional_headers_cb
User supplied callback function to call when optional headers need to be sent.
Definition client.h:308
http_response_cb_t response
User supplied callback function to call when response is received.
Definition client.h:249
uint8_t * recv_buf
User supplied buffer where received data is stored.
Definition client.h:258
struct http_client_internal_data internal
HTTP client request internal data.
Definition client.h:239
const char * port
Port number to be used in the request.
Definition client.h:284
enum http_method method
The HTTP method: GET, HEAD, OPTIONS, POST, ...
Definition client.h:244
const char * payload
Payload, may be NULL.
Definition client.h:295
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:255
HTTP response from the server.
Definition client.h:105
uint8_t cl_present
Is Content-Length field present.
Definition client.h:206
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
struct http_content_range content_range
HTTP Content-Range response field value.
Definition client.h:204
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:208
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:207
uint8_t cr_present
Is Content-Range field present.
Definition client.h:209
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