esp_http_client.h 24 KB

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