esp_http_client.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ESP_HTTP_CLIENT_H
  7. #define _ESP_HTTP_CLIENT_H
  8. #include "freertos/FreeRTOS.h"
  9. #include "http_parser.h"
  10. #include "sdkconfig.h"
  11. #include "esp_err.h"
  12. #include <sys/socket.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define DEFAULT_HTTP_BUF_SIZE (512)
  17. typedef struct esp_http_client *esp_http_client_handle_t;
  18. typedef struct esp_http_client_event *esp_http_client_event_handle_t;
  19. /**
  20. * @brief HTTP Client events id
  21. */
  22. typedef enum {
  23. HTTP_EVENT_ERROR = 0, /*!< This event occurs when there are any errors during execution */
  24. HTTP_EVENT_ON_CONNECTED, /*!< Once the HTTP has been connected to the server, no data exchange has been performed */
  25. HTTP_EVENT_HEADERS_SENT, /*!< After sending all the headers to the server */
  26. HTTP_EVENT_HEADER_SENT = HTTP_EVENT_HEADERS_SENT, /*!< This header has been kept for backward compatability
  27. and will be deprecated in future versions esp-idf */
  28. HTTP_EVENT_ON_HEADER, /*!< Occurs when receiving each header sent from the server */
  29. HTTP_EVENT_ON_DATA, /*!< Occurs when receiving data from the server, possibly multiple portions of the packet */
  30. HTTP_EVENT_ON_FINISH, /*!< Occurs when finish a HTTP session */
  31. HTTP_EVENT_DISCONNECTED, /*!< The connection has been disconnected */
  32. } esp_http_client_event_id_t;
  33. /**
  34. * @brief HTTP Client events data
  35. */
  36. typedef struct esp_http_client_event {
  37. esp_http_client_event_id_t event_id; /*!< event_id, to know the cause of the event */
  38. esp_http_client_handle_t client; /*!< esp_http_client_handle_t context */
  39. void *data; /*!< data of the event */
  40. int data_len; /*!< data length of data */
  41. void *user_data; /*!< user_data context, from esp_http_client_config_t user_data */
  42. char *header_key; /*!< For HTTP_EVENT_ON_HEADER event_id, it's store current http header key */
  43. char *header_value; /*!< For HTTP_EVENT_ON_HEADER event_id, it's store current http header value */
  44. } esp_http_client_event_t;
  45. /**
  46. * @brief HTTP Client transport
  47. */
  48. typedef enum {
  49. HTTP_TRANSPORT_UNKNOWN = 0x0, /*!< Unknown */
  50. HTTP_TRANSPORT_OVER_TCP, /*!< Transport over tcp */
  51. HTTP_TRANSPORT_OVER_SSL, /*!< Transport over ssl */
  52. } esp_http_client_transport_t;
  53. typedef esp_err_t (*http_event_handle_cb)(esp_http_client_event_t *evt);
  54. /**
  55. * @brief HTTP method
  56. */
  57. typedef enum {
  58. HTTP_METHOD_GET = 0, /*!< HTTP GET Method */
  59. HTTP_METHOD_POST, /*!< HTTP POST Method */
  60. HTTP_METHOD_PUT, /*!< HTTP PUT Method */
  61. HTTP_METHOD_PATCH, /*!< HTTP PATCH Method */
  62. HTTP_METHOD_DELETE, /*!< HTTP DELETE Method */
  63. HTTP_METHOD_HEAD, /*!< HTTP HEAD Method */
  64. HTTP_METHOD_NOTIFY, /*!< HTTP NOTIFY Method */
  65. HTTP_METHOD_SUBSCRIBE, /*!< HTTP SUBSCRIBE Method */
  66. HTTP_METHOD_UNSUBSCRIBE,/*!< HTTP UNSUBSCRIBE Method */
  67. HTTP_METHOD_OPTIONS, /*!< HTTP OPTIONS Method */
  68. HTTP_METHOD_COPY, /*!< HTTP COPY Method */
  69. HTTP_METHOD_MOVE, /*!< HTTP MOVE Method */
  70. HTTP_METHOD_LOCK, /*!< HTTP LOCK Method */
  71. HTTP_METHOD_UNLOCK, /*!< HTTP UNLOCK Method */
  72. HTTP_METHOD_PROPFIND, /*!< HTTP PROPFIND Method */
  73. HTTP_METHOD_PROPPATCH, /*!< HTTP PROPPATCH Method */
  74. HTTP_METHOD_MKCOL, /*!< HTTP MKCOL Method */
  75. HTTP_METHOD_MAX,
  76. } esp_http_client_method_t;
  77. /**
  78. * @brief HTTP Authentication type
  79. */
  80. typedef enum {
  81. HTTP_AUTH_TYPE_NONE = 0, /*!< No authention */
  82. HTTP_AUTH_TYPE_BASIC, /*!< HTTP Basic authentication */
  83. HTTP_AUTH_TYPE_DIGEST, /*!< HTTP Disgest authentication */
  84. } esp_http_client_auth_type_t;
  85. /**
  86. * @brief HTTP configuration
  87. */
  88. typedef struct {
  89. const char *url; /*!< HTTP URL, the information on the URL is most important, it overrides the other fields below, if any */
  90. const char *host; /*!< Domain or IP as string */
  91. int port; /*!< Port to connect, default depend on esp_http_client_transport_t (80 or 443) */
  92. const char *username; /*!< Using for Http authentication */
  93. const char *password; /*!< Using for Http authentication */
  94. esp_http_client_auth_type_t auth_type; /*!< Http authentication type, see `esp_http_client_auth_type_t` */
  95. const char *path; /*!< HTTP Path, if not set, default is `/` */
  96. const char *query; /*!< HTTP query */
  97. const char *cert_pem; /*!< SSL server certification, PEM format as string, if the client requires to verify server */
  98. size_t cert_len; /*!< Length of the buffer pointed to by cert_pem. May be 0 for null-terminated pem */
  99. const char *client_cert_pem; /*!< SSL client certification, PEM format as string, if the server requires to verify client */
  100. size_t client_cert_len; /*!< Length of the buffer pointed to by client_cert_pem. May be 0 for null-terminated pem */
  101. const char *client_key_pem; /*!< SSL client key, PEM format as string, if the server requires to verify client */
  102. size_t client_key_len; /*!< Length of the buffer pointed to by client_key_pem. May be 0 for null-terminated pem */
  103. const char *user_agent; /*!< The User Agent string to send with HTTP requests */
  104. esp_http_client_method_t method; /*!< HTTP Method */
  105. int timeout_ms; /*!< Network timeout in milliseconds */
  106. bool disable_auto_redirect; /*!< Disable HTTP automatic redirects */
  107. int max_redirection_count; /*!< Max number of redirections on receiving HTTP redirect status code, using default value if zero*/
  108. int max_authorization_retries; /*!< Max connection retries on receiving HTTP unauthorized status code, using default value if zero. Disables authorization retry if -1*/
  109. http_event_handle_cb event_handler; /*!< HTTP Event Handle */
  110. esp_http_client_transport_t transport_type; /*!< HTTP transport type, see `esp_http_client_transport_t` */
  111. int buffer_size; /*!< HTTP receive buffer size */
  112. int buffer_size_tx; /*!< HTTP transmit buffer size */
  113. void *user_data; /*!< HTTP user_data context */
  114. bool is_async; /*!< Set asynchronous mode, only supported with HTTPS for now */
  115. bool use_global_ca_store; /*!< Use a global ca_store for all the connections in which this bool is set. */
  116. bool skip_cert_common_name_check; /*!< Skip any validation of server certificate CN field */
  117. esp_err_t (*crt_bundle_attach)(void *conf); /*!< Function pointer to esp_crt_bundle_attach. Enables the use of certification
  118. bundle for server verification, must be enabled in menuconfig */
  119. bool keep_alive_enable; /*!< Enable keep-alive timeout */
  120. int keep_alive_idle; /*!< Keep-alive idle time. Default is 5 (second) */
  121. int keep_alive_interval; /*!< Keep-alive interval time. Default is 5 (second) */
  122. int keep_alive_count; /*!< Keep-alive packet retry send count. Default is 3 counts */
  123. struct ifreq *if_name; /*!< The name of interface for data to go through. Use the default interface without setting */
  124. } esp_http_client_config_t;
  125. /**
  126. * Enum for the HTTP status codes.
  127. */
  128. typedef enum {
  129. /* 2xx - Success */
  130. HttpStatus_Ok = 200,
  131. /* 3xx - Redirection */
  132. HttpStatus_MultipleChoices = 300,
  133. HttpStatus_MovedPermanently = 301,
  134. HttpStatus_Found = 302,
  135. HttpStatus_TemporaryRedirect = 307,
  136. /* 4xx - Client Error */
  137. HttpStatus_Unauthorized = 401,
  138. HttpStatus_Forbidden = 403,
  139. HttpStatus_NotFound = 404,
  140. /* 5xx - Server Error */
  141. HttpStatus_InternalError = 500
  142. } HttpStatus_Code;
  143. #define ESP_ERR_HTTP_BASE (0x7000) /*!< Starting number of HTTP error codes */
  144. #define ESP_ERR_HTTP_MAX_REDIRECT (ESP_ERR_HTTP_BASE + 1) /*!< The error exceeds the number of HTTP redirects */
  145. #define ESP_ERR_HTTP_CONNECT (ESP_ERR_HTTP_BASE + 2) /*!< Error open the HTTP connection */
  146. #define ESP_ERR_HTTP_WRITE_DATA (ESP_ERR_HTTP_BASE + 3) /*!< Error write HTTP data */
  147. #define ESP_ERR_HTTP_FETCH_HEADER (ESP_ERR_HTTP_BASE + 4) /*!< Error read HTTP header from server */
  148. #define ESP_ERR_HTTP_INVALID_TRANSPORT (ESP_ERR_HTTP_BASE + 5) /*!< There are no transport support for the input scheme */
  149. #define ESP_ERR_HTTP_CONNECTING (ESP_ERR_HTTP_BASE + 6) /*!< HTTP connection hasn't been established yet */
  150. #define ESP_ERR_HTTP_EAGAIN (ESP_ERR_HTTP_BASE + 7) /*!< Mapping of errno EAGAIN to esp_err_t */
  151. /**
  152. * @brief Start a HTTP session
  153. * This function must be the first function to call,
  154. * and it returns a esp_http_client_handle_t that you must use as input to other functions in the interface.
  155. * This call MUST have a corresponding call to esp_http_client_cleanup when the operation is complete.
  156. *
  157. * @param[in] config The configurations, see `http_client_config_t`
  158. *
  159. * @return
  160. * - `esp_http_client_handle_t`
  161. * - NULL if any errors
  162. */
  163. esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *config);
  164. /**
  165. * @brief Invoke this function after `esp_http_client_init` and all the options calls are made, and will perform the
  166. * transfer as described in the options. It must be called with the same esp_http_client_handle_t as input as the esp_http_client_init call returned.
  167. * esp_http_client_perform performs the entire request in either blocking or non-blocking manner. By default, the API performs request in a blocking manner and returns when done,
  168. * or if it failed, and in non-blocking manner, it returns if EAGAIN/EWOULDBLOCK or EINPROGRESS is encountered, or if it failed. And in case of non-blocking request,
  169. * the user may call this API multiple times unless request & response is complete or there is a failure. To enable non-blocking esp_http_client_perform(), `is_async` member of esp_http_client_config_t
  170. * must be set while making a call to esp_http_client_init() API.
  171. * You can do any amount of calls to esp_http_client_perform while using the same esp_http_client_handle_t. The underlying connection may be kept open if the server allows it.
  172. * If you intend to transfer more than one file, you are even encouraged to do so.
  173. * esp_http_client will then attempt to re-use the same connection for the following transfers, thus making the operations faster, less CPU intense and using less network resources.
  174. * Just note that you will have to use `esp_http_client_set_**` between the invokes to set options for the following esp_http_client_perform.
  175. *
  176. * @note You must never call this function simultaneously from two places using the same client handle.
  177. * Let the function return first before invoking it another time.
  178. * If you want parallel transfers, you must use several esp_http_client_handle_t.
  179. * This function include `esp_http_client_open` -> `esp_http_client_write` -> `esp_http_client_fetch_headers` -> `esp_http_client_read` (and option) `esp_http_client_close`.
  180. *
  181. * @param client The esp_http_client handle
  182. *
  183. * @return
  184. * - ESP_OK on successful
  185. * - ESP_FAIL on error
  186. */
  187. esp_err_t esp_http_client_perform(esp_http_client_handle_t client);
  188. /**
  189. * @brief Set URL for client, when performing this behavior, the options in the URL will replace the old ones
  190. *
  191. * @param[in] client The esp_http_client handle
  192. * @param[in] url The url
  193. *
  194. * @return
  195. * - ESP_OK
  196. * - ESP_FAIL
  197. */
  198. esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *url);
  199. /**
  200. * @brief Set post data, this function must be called before `esp_http_client_perform`.
  201. * Note: The data parameter passed to this function is a pointer and this function will not copy the data
  202. *
  203. * @param[in] client The esp_http_client handle
  204. * @param[in] data post data pointer
  205. * @param[in] len post length
  206. *
  207. * @return
  208. * - ESP_OK
  209. * - ESP_FAIL
  210. */
  211. esp_err_t esp_http_client_set_post_field(esp_http_client_handle_t client, const char *data, int len);
  212. /**
  213. * @brief Get current post field information
  214. *
  215. * @param[in] client The client
  216. * @param[out] data Point to post data pointer
  217. *
  218. * @return Size of post data
  219. */
  220. int esp_http_client_get_post_field(esp_http_client_handle_t client, char **data);
  221. /**
  222. * @brief Set http request header, this function must be called after esp_http_client_init and before any
  223. * perform function
  224. *
  225. * @param[in] client The esp_http_client handle
  226. * @param[in] key The header key
  227. * @param[in] value The header value
  228. *
  229. * @return
  230. * - ESP_OK
  231. * - ESP_FAIL
  232. */
  233. esp_err_t esp_http_client_set_header(esp_http_client_handle_t client, const char *key, const char *value);
  234. /**
  235. * @brief Get http request header.
  236. * The value parameter will be set to NULL if there is no header which is same as
  237. * the key specified, otherwise the address of header value will be assigned to value parameter.
  238. * This function must be called after `esp_http_client_init`.
  239. *
  240. * @param[in] client The esp_http_client handle
  241. * @param[in] key The header key
  242. * @param[out] value The header value
  243. *
  244. * @return
  245. * - ESP_OK
  246. * - ESP_FAIL
  247. */
  248. esp_err_t esp_http_client_get_header(esp_http_client_handle_t client, const char *key, char **value);
  249. /**
  250. * @brief Get http request username.
  251. * The address of username buffer will be assigned to value parameter.
  252. * This function must be called after `esp_http_client_init`.
  253. *
  254. * @param[in] client The esp_http_client handle
  255. * @param[out] value The username value
  256. *
  257. * @return
  258. * - ESP_OK
  259. * - ESP_ERR_INVALID_ARG
  260. */
  261. esp_err_t esp_http_client_get_username(esp_http_client_handle_t client, char **value);
  262. /**
  263. * @brief Set http request username.
  264. * The value of username parameter will be assigned to username buffer.
  265. * If the username parameter is NULL then username buffer will be freed.
  266. *
  267. * @param[in] client The esp_http_client handle
  268. * @param[in] username The username value
  269. *
  270. * @return
  271. * - ESP_OK
  272. * - ESP_ERR_INVALID_ARG
  273. */
  274. esp_err_t esp_http_client_set_username(esp_http_client_handle_t client, const char *username);
  275. /**
  276. * @brief Get http request password.
  277. * The address of password buffer will be assigned to value parameter.
  278. * This function must be called after `esp_http_client_init`.
  279. *
  280. * @param[in] client The esp_http_client handle
  281. * @param[out] value The password value
  282. *
  283. * @return
  284. * - ESP_OK
  285. * - ESP_ERR_INVALID_ARG
  286. */
  287. esp_err_t esp_http_client_get_password(esp_http_client_handle_t client, char **value);
  288. /**
  289. * @brief Set http request password.
  290. * The value of password parameter will be assigned to password buffer.
  291. * If the password parameter is NULL then password buffer will be freed.
  292. *
  293. * @param[in] client The esp_http_client handle
  294. * @param[in] password The password value
  295. *
  296. * @return
  297. * - ESP_OK
  298. * - ESP_ERR_INVALID_ARG
  299. */
  300. esp_err_t esp_http_client_set_password(esp_http_client_handle_t client, const char *password);
  301. /**
  302. * @brief Set http request auth_type.
  303. *
  304. * @param[in] client The esp_http_client handle
  305. * @param[in] auth_type The esp_http_client auth type
  306. *
  307. * @return
  308. * - ESP_OK
  309. * - ESP_ERR_INVALID_ARG
  310. */
  311. esp_err_t esp_http_client_set_authtype(esp_http_client_handle_t client, esp_http_client_auth_type_t auth_type);
  312. /**
  313. * @brief Set http request method
  314. *
  315. * @param[in] client The esp_http_client handle
  316. * @param[in] method The method
  317. *
  318. * @return
  319. * - ESP_OK
  320. * - ESP_ERR_INVALID_ARG
  321. */
  322. esp_err_t esp_http_client_set_method(esp_http_client_handle_t client, esp_http_client_method_t method);
  323. /**
  324. * @brief Set http request timeout
  325. *
  326. * @param[in] client The esp_http_client handle
  327. * @param[in] timeout_ms The timeout value
  328. *
  329. * @return
  330. * - ESP_OK
  331. * - ESP_ERR_INVALID_ARG
  332. */
  333. esp_err_t esp_http_client_set_timeout_ms(esp_http_client_handle_t client, int timeout_ms);
  334. /**
  335. * @brief Delete http request header
  336. *
  337. * @param[in] client The esp_http_client handle
  338. * @param[in] key The key
  339. *
  340. * @return
  341. * - ESP_OK
  342. * - ESP_FAIL
  343. */
  344. esp_err_t esp_http_client_delete_header(esp_http_client_handle_t client, const char *key);
  345. /**
  346. * @brief This function will be open the connection, write all header strings and return
  347. *
  348. * @param[in] client The esp_http_client handle
  349. * @param[in] write_len HTTP Content length need to write to the server
  350. *
  351. * @return
  352. * - ESP_OK
  353. * - ESP_FAIL
  354. */
  355. esp_err_t esp_http_client_open(esp_http_client_handle_t client, int write_len);
  356. /**
  357. * @brief This function will write data to the HTTP connection previously opened by esp_http_client_open()
  358. *
  359. * @param[in] client The esp_http_client handle
  360. * @param buffer The buffer
  361. * @param[in] len This value must not be larger than the write_len parameter provided to esp_http_client_open()
  362. *
  363. * @return
  364. * - (-1) if any errors
  365. * - Length of data written
  366. */
  367. int esp_http_client_write(esp_http_client_handle_t client, const char *buffer, int len);
  368. /**
  369. * @brief This function need to call after esp_http_client_open, it will read from http stream, process all receive headers
  370. *
  371. * @param[in] client The esp_http_client handle
  372. *
  373. * @return
  374. * - (0) if stream doesn't contain content-length header, or chunked encoding (checked by `esp_http_client_is_chunked` response)
  375. * - (-1: ESP_FAIL) if any errors
  376. * - Download data length defined by content-length header
  377. */
  378. int esp_http_client_fetch_headers(esp_http_client_handle_t client);
  379. /**
  380. * @brief Check response data is chunked
  381. *
  382. * @param[in] client The esp_http_client handle
  383. *
  384. * @return true or false
  385. */
  386. bool esp_http_client_is_chunked_response(esp_http_client_handle_t client);
  387. /**
  388. * @brief Read data from http stream
  389. *
  390. * @param[in] client The esp_http_client handle
  391. * @param buffer The buffer
  392. * @param[in] len The length
  393. *
  394. * @return
  395. * - (-1) if any errors
  396. * - Length of data was read
  397. */
  398. int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len);
  399. /**
  400. * @brief Get http response status code, the valid value if this function invoke after `esp_http_client_perform`
  401. *
  402. * @param[in] client The esp_http_client handle
  403. *
  404. * @return Status code
  405. */
  406. int esp_http_client_get_status_code(esp_http_client_handle_t client);
  407. /**
  408. * @brief Get http response content length (from header Content-Length)
  409. * the valid value if this function invoke after `esp_http_client_perform`
  410. *
  411. * @param[in] client The esp_http_client handle
  412. *
  413. * @return
  414. * - (-1) Chunked transfer
  415. * - Content-Length value as bytes
  416. */
  417. int esp_http_client_get_content_length(esp_http_client_handle_t client);
  418. /**
  419. * @brief Close http connection, still kept all http request resources
  420. *
  421. * @param[in] client The esp_http_client handle
  422. *
  423. * @return
  424. * - ESP_OK
  425. * - ESP_FAIL
  426. */
  427. esp_err_t esp_http_client_close(esp_http_client_handle_t client);
  428. /**
  429. * @brief This function must be the last function to call for an session.
  430. * It is the opposite of the esp_http_client_init function and must be called with the same handle as input that a esp_http_client_init call returned.
  431. * This might close all connections this handle has used and possibly has kept open until now.
  432. * Don't call this function if you intend to transfer more files, re-using handles is a key to good performance with esp_http_client.
  433. *
  434. * @param[in] client The esp_http_client handle
  435. *
  436. * @return
  437. * - ESP_OK
  438. * - ESP_FAIL
  439. */
  440. esp_err_t esp_http_client_cleanup(esp_http_client_handle_t client);
  441. /**
  442. * @brief Get transport type
  443. *
  444. * @param[in] client The esp_http_client handle
  445. *
  446. * @return
  447. * - HTTP_TRANSPORT_UNKNOWN
  448. * - HTTP_TRANSPORT_OVER_TCP
  449. * - HTTP_TRANSPORT_OVER_SSL
  450. */
  451. esp_http_client_transport_t esp_http_client_get_transport_type(esp_http_client_handle_t client);
  452. /**
  453. * @brief Set redirection URL.
  454. * When received the 30x code from the server, the client stores the redirect URL provided by the server.
  455. * This function will set the current URL to redirect to enable client to execute the redirection request.
  456. *
  457. * @param[in] client The esp_http_client handle
  458. *
  459. * @return
  460. * - ESP_OK
  461. * - ESP_FAIL
  462. */
  463. esp_err_t esp_http_client_set_redirection(esp_http_client_handle_t client);
  464. /**
  465. * @brief On receiving HTTP Status code 401, this API can be invoked to add authorization
  466. * information.
  467. *
  468. * @note There is a possibility of receiving body message with redirection status codes, thus make sure
  469. * to flush off body data after calling this API.
  470. *
  471. * @param[in] client The esp_http_client handle
  472. */
  473. void esp_http_client_add_auth(esp_http_client_handle_t client);
  474. /**
  475. * @brief Checks if entire data in the response has been read without any error.
  476. *
  477. * @param[in] client The esp_http_client handle
  478. *
  479. * @return
  480. * - true
  481. * - false
  482. */
  483. bool esp_http_client_is_complete_data_received(esp_http_client_handle_t client);
  484. /**
  485. * @brief Helper API to read larger data chunks
  486. * This is a helper API which internally calls `esp_http_client_read` multiple times till the end of data is reached or till the buffer gets full.
  487. *
  488. * @param[in] client The esp_http_client handle
  489. * @param buffer The buffer
  490. * @param[in] len The buffer length
  491. *
  492. * @return
  493. * - Length of data was read
  494. */
  495. int esp_http_client_read_response(esp_http_client_handle_t client, char *buffer, int len);
  496. /**
  497. * @brief Process all remaining response data
  498. * This uses an internal buffer to repeatedly receive, parse, and discard response data until complete data is processed.
  499. * As no additional user-supplied buffer is required, this may be preferrable to `esp_http_client_read_response` in situations where the content of the response may be ignored.
  500. *
  501. * @param[in] client The esp_http_client handle
  502. * @param len Length of data discarded
  503. *
  504. * @return
  505. * - ESP_OK If successful, len will have discarded length
  506. * - ESP_FAIL If failed to read response
  507. * - ESP_ERR_INVALID_ARG If the client is NULL
  508. */
  509. esp_err_t esp_http_client_flush_response(esp_http_client_handle_t client, int *len);
  510. /**
  511. * @brief Get URL from client
  512. *
  513. * @param[in] client The esp_http_client handle
  514. * @param[inout] url The buffer to store URL
  515. * @param[in] len The buffer length
  516. *
  517. * @return
  518. * - ESP_OK
  519. * - ESP_FAIL
  520. */
  521. esp_err_t esp_http_client_get_url(esp_http_client_handle_t client, char *url, const int len);
  522. /**
  523. * @brief Get Chunk-Length from client
  524. *
  525. * @param[in] client The esp_http_client handle
  526. * @param[out] len Variable to store length
  527. *
  528. * @return
  529. * - ESP_OK If successful, len will have length of current chunk
  530. * - ESP_FAIL If the server is not a chunked server
  531. * - ESP_ERR_INVALID_ARG If the client or len are NULL
  532. */
  533. esp_err_t esp_http_client_get_chunk_length(esp_http_client_handle_t client, int *len);
  534. #ifdef __cplusplus
  535. }
  536. #endif
  537. #endif