esp_http_server.h 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  1. // Copyright 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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _ESP_HTTP_SERVER_H_
  15. #define _ESP_HTTP_SERVER_H_
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <freertos/FreeRTOS.h>
  19. #include <freertos/task.h>
  20. #include <http_parser.h>
  21. #include <sdkconfig.h>
  22. #include <esp_err.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /*
  27. note: esp_https_server.h includes a customized copy of this
  28. initializer that should be kept in sync
  29. */
  30. #define HTTPD_DEFAULT_CONFIG() { \
  31. .task_priority = tskIDLE_PRIORITY+5, \
  32. .stack_size = 4096, \
  33. .core_id = tskNO_AFFINITY, \
  34. .server_port = 80, \
  35. .ctrl_port = 32768, \
  36. .max_open_sockets = 7, \
  37. .max_uri_handlers = 8, \
  38. .max_resp_headers = 8, \
  39. .backlog_conn = 5, \
  40. .lru_purge_enable = false, \
  41. .recv_wait_timeout = 5, \
  42. .send_wait_timeout = 5, \
  43. .global_user_ctx = NULL, \
  44. .global_user_ctx_free_fn = NULL, \
  45. .global_transport_ctx = NULL, \
  46. .global_transport_ctx_free_fn = NULL, \
  47. .open_fn = NULL, \
  48. .close_fn = NULL, \
  49. .uri_match_fn = NULL \
  50. }
  51. #define ESP_ERR_HTTPD_BASE (0xb000) /*!< Starting number of HTTPD error codes */
  52. #define ESP_ERR_HTTPD_HANDLERS_FULL (ESP_ERR_HTTPD_BASE + 1) /*!< All slots for registering URI handlers have been consumed */
  53. #define ESP_ERR_HTTPD_HANDLER_EXISTS (ESP_ERR_HTTPD_BASE + 2) /*!< URI handler with same method and target URI already registered */
  54. #define ESP_ERR_HTTPD_INVALID_REQ (ESP_ERR_HTTPD_BASE + 3) /*!< Invalid request pointer */
  55. #define ESP_ERR_HTTPD_RESULT_TRUNC (ESP_ERR_HTTPD_BASE + 4) /*!< Result string truncated */
  56. #define ESP_ERR_HTTPD_RESP_HDR (ESP_ERR_HTTPD_BASE + 5) /*!< Response header field larger than supported */
  57. #define ESP_ERR_HTTPD_RESP_SEND (ESP_ERR_HTTPD_BASE + 6) /*!< Error occured while sending response packet */
  58. #define ESP_ERR_HTTPD_ALLOC_MEM (ESP_ERR_HTTPD_BASE + 7) /*!< Failed to dynamically allocate memory for resource */
  59. #define ESP_ERR_HTTPD_TASK (ESP_ERR_HTTPD_BASE + 8) /*!< Failed to launch server task/thread */
  60. /* Symbol to be used as length parameter in httpd_resp_send APIs
  61. * for setting buffer length to string length */
  62. #define HTTPD_RESP_USE_STRLEN -1
  63. /* ************** Group: Initialization ************** */
  64. /** @name Initialization
  65. * APIs related to the Initialization of the web server
  66. * @{
  67. */
  68. /**
  69. * @brief HTTP Server Instance Handle
  70. *
  71. * Every instance of the server will have a unique handle.
  72. */
  73. typedef void* httpd_handle_t;
  74. /**
  75. * @brief HTTP Method Type wrapper over "enum http_method"
  76. * available in "http_parser" library
  77. */
  78. typedef enum http_method httpd_method_t;
  79. /**
  80. * @brief Prototype for freeing context data (if any)
  81. * @param[in] ctx object to free
  82. */
  83. typedef void (*httpd_free_ctx_fn_t)(void *ctx);
  84. /**
  85. * @brief Function prototype for opening a session.
  86. *
  87. * Called immediately after the socket was opened to set up the send/recv functions and
  88. * other parameters of the socket.
  89. *
  90. * @param[in] hd server instance
  91. * @param[in] sockfd session socket file descriptor
  92. * @return
  93. * - ESP_OK : On success
  94. * - Any value other than ESP_OK will signal the server to close the socket immediately
  95. */
  96. typedef esp_err_t (*httpd_open_func_t)(httpd_handle_t hd, int sockfd);
  97. /**
  98. * @brief Function prototype for closing a session.
  99. *
  100. * @note It's possible that the socket descriptor is invalid at this point, the function
  101. * is called for all terminated sessions. Ensure proper handling of return codes.
  102. *
  103. * @param[in] hd server instance
  104. * @param[in] sockfd session socket file descriptor
  105. */
  106. typedef void (*httpd_close_func_t)(httpd_handle_t hd, int sockfd);
  107. /**
  108. * @brief Function prototype for URI matching.
  109. *
  110. * @param[in] reference_uri URI/template with respect to which the other URI is matched
  111. * @param[in] uri_to_match URI/template being matched to the reference URI/template
  112. * @param[in] match_upto For specifying the actual length of `uri_to_match` up to
  113. * which the matching algorithm is to be applied (The maximum
  114. * value is `strlen(uri_to_match)`, independent of the length
  115. * of `reference_uri`)
  116. * @return true on match
  117. */
  118. typedef bool (*httpd_uri_match_func_t)(const char *reference_uri,
  119. const char *uri_to_match,
  120. size_t match_upto);
  121. /**
  122. * @brief HTTP Server Configuration Structure
  123. *
  124. * @note Use HTTPD_DEFAULT_CONFIG() to initialize the configuration
  125. * to a default value and then modify only those fields that are
  126. * specifically determined by the use case.
  127. */
  128. typedef struct httpd_config {
  129. unsigned task_priority; /*!< Priority of FreeRTOS task which runs the server */
  130. size_t stack_size; /*!< The maximum stack size allowed for the server task */
  131. BaseType_t core_id; /*!< The core the HTTP server task will run on */
  132. /**
  133. * TCP Port number for receiving and transmitting HTTP traffic
  134. */
  135. uint16_t server_port;
  136. /**
  137. * UDP Port number for asynchronously exchanging control signals
  138. * between various components of the server
  139. */
  140. uint16_t ctrl_port;
  141. uint16_t max_open_sockets; /*!< Max number of sockets/clients connected at any time*/
  142. uint16_t max_uri_handlers; /*!< Maximum allowed uri handlers */
  143. uint16_t max_resp_headers; /*!< Maximum allowed additional headers in HTTP response */
  144. uint16_t backlog_conn; /*!< Number of backlog connections */
  145. bool lru_purge_enable; /*!< Purge "Least Recently Used" connection */
  146. uint16_t recv_wait_timeout; /*!< Timeout for recv function (in seconds)*/
  147. uint16_t send_wait_timeout; /*!< Timeout for send function (in seconds)*/
  148. /**
  149. * Global user context.
  150. *
  151. * This field can be used to store arbitrary user data within the server context.
  152. * The value can be retrieved using the server handle, available e.g. in the httpd_req_t struct.
  153. *
  154. * When shutting down, the server frees up the user context by
  155. * calling free() on the global_user_ctx field. If you wish to use a custom
  156. * function for freeing the global user context, please specify that here.
  157. */
  158. void * global_user_ctx;
  159. /**
  160. * Free function for global user context
  161. */
  162. httpd_free_ctx_fn_t global_user_ctx_free_fn;
  163. /**
  164. * Global transport context.
  165. *
  166. * Similar to global_user_ctx, but used for session encoding or encryption (e.g. to hold the SSL context).
  167. * It will be freed using free(), unless global_transport_ctx_free_fn is specified.
  168. */
  169. void * global_transport_ctx;
  170. /**
  171. * Free function for global transport context
  172. */
  173. httpd_free_ctx_fn_t global_transport_ctx_free_fn;
  174. /**
  175. * Custom session opening callback.
  176. *
  177. * Called on a new session socket just after accept(), but before reading any data.
  178. *
  179. * This is an opportunity to set up e.g. SSL encryption using global_transport_ctx
  180. * and the send/recv/pending session overrides.
  181. *
  182. * If a context needs to be maintained between these functions, store it in the session using
  183. * httpd_sess_set_transport_ctx() and retrieve it later with httpd_sess_get_transport_ctx()
  184. *
  185. * Returning a value other than ESP_OK will immediately close the new socket.
  186. */
  187. httpd_open_func_t open_fn;
  188. /**
  189. * Custom session closing callback.
  190. *
  191. * Called when a session is deleted, before freeing user and transport contexts and before
  192. * closing the socket. This is a place for custom de-init code common to all sockets.
  193. *
  194. * Set the user or transport context to NULL if it was freed here, so the server does not
  195. * try to free it again.
  196. *
  197. * This function is run for all terminated sessions, including sessions where the socket
  198. * was closed by the network stack - that is, the file descriptor may not be valid anymore.
  199. */
  200. httpd_close_func_t close_fn;
  201. /**
  202. * URI matcher function.
  203. *
  204. * Called when searching for a matching URI:
  205. * 1) whose request handler is to be executed right
  206. * after an HTTP request is successfully parsed
  207. * 2) in order to prevent duplication while registering
  208. * a new URI handler using `httpd_register_uri_handler()`
  209. *
  210. * Available options are:
  211. * 1) NULL : Internally do basic matching using `strncmp()`
  212. * 2) `httpd_uri_match_wildcard()` : URI wildcard matcher
  213. *
  214. * Users can implement their own matching functions (See description
  215. * of the `httpd_uri_match_func_t` function prototype)
  216. */
  217. httpd_uri_match_func_t uri_match_fn;
  218. } httpd_config_t;
  219. /**
  220. * @brief Starts the web server
  221. *
  222. * Create an instance of HTTP server and allocate memory/resources for it
  223. * depending upon the specified configuration.
  224. *
  225. * Example usage:
  226. * @code{c}
  227. *
  228. * //Function for starting the webserver
  229. * httpd_handle_t start_webserver(void)
  230. * {
  231. * // Generate default configuration
  232. * httpd_config_t config = HTTPD_DEFAULT_CONFIG();
  233. *
  234. * // Empty handle to http_server
  235. * httpd_handle_t server = NULL;
  236. *
  237. * // Start the httpd server
  238. * if (httpd_start(&server, &config) == ESP_OK) {
  239. * // Register URI handlers
  240. * httpd_register_uri_handler(server, &uri_get);
  241. * httpd_register_uri_handler(server, &uri_post);
  242. * }
  243. * // If server failed to start, handle will be NULL
  244. * return server;
  245. * }
  246. *
  247. * @endcode
  248. *
  249. * @param[in] config Configuration for new instance of the server
  250. * @param[out] handle Handle to newly created instance of the server. NULL on error
  251. * @return
  252. * - ESP_OK : Instance created successfully
  253. * - ESP_ERR_INVALID_ARG : Null argument(s)
  254. * - ESP_ERR_HTTPD_ALLOC_MEM : Failed to allocate memory for instance
  255. * - ESP_ERR_HTTPD_TASK : Failed to launch server task
  256. */
  257. esp_err_t httpd_start(httpd_handle_t *handle, const httpd_config_t *config);
  258. /**
  259. * @brief Stops the web server
  260. *
  261. * Deallocates memory/resources used by an HTTP server instance and
  262. * deletes it. Once deleted the handle can no longer be used for accessing
  263. * the instance.
  264. *
  265. * Example usage:
  266. * @code{c}
  267. *
  268. * // Function for stopping the webserver
  269. * void stop_webserver(httpd_handle_t server)
  270. * {
  271. * // Ensure handle is non NULL
  272. * if (server != NULL) {
  273. * // Stop the httpd server
  274. * httpd_stop(server);
  275. * }
  276. * }
  277. *
  278. * @endcode
  279. *
  280. * @param[in] handle Handle to server returned by httpd_start
  281. * @return
  282. * - ESP_OK : Server stopped successfully
  283. * - ESP_ERR_INVALID_ARG : Handle argument is Null
  284. */
  285. esp_err_t httpd_stop(httpd_handle_t handle);
  286. /** End of Group Initialization
  287. * @}
  288. */
  289. /* ************** Group: URI Handlers ************** */
  290. /** @name URI Handlers
  291. * APIs related to the URI handlers
  292. * @{
  293. */
  294. /* Max supported HTTP request header length */
  295. #define HTTPD_MAX_REQ_HDR_LEN CONFIG_HTTPD_MAX_REQ_HDR_LEN
  296. /* Max supported HTTP request URI length */
  297. #define HTTPD_MAX_URI_LEN CONFIG_HTTPD_MAX_URI_LEN
  298. /**
  299. * @brief HTTP Request Data Structure
  300. */
  301. typedef struct httpd_req {
  302. httpd_handle_t handle; /*!< Handle to server instance */
  303. int method; /*!< The type of HTTP request, -1 if unsupported method */
  304. const char uri[HTTPD_MAX_URI_LEN + 1]; /*!< The URI of this request (1 byte extra for null termination) */
  305. size_t content_len; /*!< Length of the request body */
  306. void *aux; /*!< Internally used members */
  307. /**
  308. * User context pointer passed during URI registration.
  309. */
  310. void *user_ctx;
  311. /**
  312. * Session Context Pointer
  313. *
  314. * A session context. Contexts are maintained across 'sessions' for a
  315. * given open TCP connection. One session could have multiple request
  316. * responses. The web server will ensure that the context persists
  317. * across all these request and responses.
  318. *
  319. * By default, this is NULL. URI Handlers can set this to any meaningful
  320. * value.
  321. *
  322. * If the underlying socket gets closed, and this pointer is non-NULL,
  323. * the web server will free up the context by calling free(), unless
  324. * free_ctx function is set.
  325. */
  326. void *sess_ctx;
  327. /**
  328. * Pointer to free context hook
  329. *
  330. * Function to free session context
  331. *
  332. * If the web server's socket closes, it frees up the session context by
  333. * calling free() on the sess_ctx member. If you wish to use a custom
  334. * function for freeing the session context, please specify that here.
  335. */
  336. httpd_free_ctx_fn_t free_ctx;
  337. /**
  338. * Flag indicating if Session Context changes should be ignored
  339. *
  340. * By default, if you change the sess_ctx in some URI handler, the http server
  341. * will internally free the earlier context (if non NULL), after the URI handler
  342. * returns. If you want to manage the allocation/reallocation/freeing of
  343. * sess_ctx yourself, set this flag to true, so that the server will not
  344. * perform any checks on it. The context will be cleared by the server
  345. * (by calling free_ctx or free()) only if the socket gets closed.
  346. */
  347. bool ignore_sess_ctx_changes;
  348. } httpd_req_t;
  349. /**
  350. * @brief Structure for URI handler
  351. */
  352. typedef struct httpd_uri {
  353. const char *uri; /*!< The URI to handle */
  354. httpd_method_t method; /*!< Method supported by the URI */
  355. /**
  356. * Handler to call for supported request method. This must
  357. * return ESP_OK, or else the underlying socket will be closed.
  358. */
  359. esp_err_t (*handler)(httpd_req_t *r);
  360. /**
  361. * Pointer to user context data which will be available to handler
  362. */
  363. void *user_ctx;
  364. #ifdef CONFIG_HTTPD_WS_SUPPORT
  365. /**
  366. * Flag for indicating a WebSocket endpoint.
  367. * If this flag is true, then method must be HTTP_GET. Otherwise the handshake will not be handled.
  368. */
  369. bool is_websocket;
  370. /**
  371. * Flag indicating that control frames (PING, PONG, CLOSE) are also passed to the handler
  372. * This is used if a custom processing of the control frames is needed
  373. */
  374. bool handle_ws_control_frames;
  375. /**
  376. * Pointer to subprotocol supported by URI
  377. */
  378. const char *supported_subprotocol;
  379. #endif
  380. } httpd_uri_t;
  381. /**
  382. * @brief Registers a URI handler
  383. *
  384. * @note URI handlers can be registered in real time as long as the
  385. * server handle is valid.
  386. *
  387. * Example usage:
  388. * @code{c}
  389. *
  390. * esp_err_t my_uri_handler(httpd_req_t* req)
  391. * {
  392. * // Recv , Process and Send
  393. * ....
  394. * ....
  395. * ....
  396. *
  397. * // Fail condition
  398. * if (....) {
  399. * // Return fail to close session //
  400. * return ESP_FAIL;
  401. * }
  402. *
  403. * // On success
  404. * return ESP_OK;
  405. * }
  406. *
  407. * // URI handler structure
  408. * httpd_uri_t my_uri {
  409. * .uri = "/my_uri/path/xyz",
  410. * .method = HTTPD_GET,
  411. * .handler = my_uri_handler,
  412. * .user_ctx = NULL
  413. * };
  414. *
  415. * // Register handler
  416. * if (httpd_register_uri_handler(server_handle, &my_uri) != ESP_OK) {
  417. * // If failed to register handler
  418. * ....
  419. * }
  420. *
  421. * @endcode
  422. *
  423. * @param[in] handle handle to HTTPD server instance
  424. * @param[in] uri_handler pointer to handler that needs to be registered
  425. *
  426. * @return
  427. * - ESP_OK : On successfully registering the handler
  428. * - ESP_ERR_INVALID_ARG : Null arguments
  429. * - ESP_ERR_HTTPD_HANDLERS_FULL : If no slots left for new handler
  430. * - ESP_ERR_HTTPD_HANDLER_EXISTS : If handler with same URI and
  431. * method is already registered
  432. */
  433. esp_err_t httpd_register_uri_handler(httpd_handle_t handle,
  434. const httpd_uri_t *uri_handler);
  435. /**
  436. * @brief Unregister a URI handler
  437. *
  438. * @param[in] handle handle to HTTPD server instance
  439. * @param[in] uri URI string
  440. * @param[in] method HTTP method
  441. *
  442. * @return
  443. * - ESP_OK : On successfully deregistering the handler
  444. * - ESP_ERR_INVALID_ARG : Null arguments
  445. * - ESP_ERR_NOT_FOUND : Handler with specified URI and method not found
  446. */
  447. esp_err_t httpd_unregister_uri_handler(httpd_handle_t handle,
  448. const char *uri, httpd_method_t method);
  449. /**
  450. * @brief Unregister all URI handlers with the specified uri string
  451. *
  452. * @param[in] handle handle to HTTPD server instance
  453. * @param[in] uri uri string specifying all handlers that need
  454. * to be deregisterd
  455. *
  456. * @return
  457. * - ESP_OK : On successfully deregistering all such handlers
  458. * - ESP_ERR_INVALID_ARG : Null arguments
  459. * - ESP_ERR_NOT_FOUND : No handler registered with specified uri string
  460. */
  461. esp_err_t httpd_unregister_uri(httpd_handle_t handle, const char* uri);
  462. /** End of URI Handlers
  463. * @}
  464. */
  465. /* ************** Group: HTTP Error ************** */
  466. /** @name HTTP Error
  467. * Prototype for HTTP errors and error handling functions
  468. * @{
  469. */
  470. /**
  471. * @brief Error codes sent as HTTP response in case of errors
  472. * encountered during processing of an HTTP request
  473. */
  474. typedef enum {
  475. /* For any unexpected errors during parsing, like unexpected
  476. * state transitions, or unhandled errors.
  477. */
  478. HTTPD_500_INTERNAL_SERVER_ERROR = 0,
  479. /* For methods not supported by http_parser. Presently
  480. * http_parser halts parsing when such methods are
  481. * encountered and so the server responds with 400 Bad
  482. * Request error instead.
  483. */
  484. HTTPD_501_METHOD_NOT_IMPLEMENTED,
  485. /* When HTTP version is not 1.1 */
  486. HTTPD_505_VERSION_NOT_SUPPORTED,
  487. /* Returned when http_parser halts parsing due to incorrect
  488. * syntax of request, unsupported method in request URI or
  489. * due to chunked encoding / upgrade field present in headers
  490. */
  491. HTTPD_400_BAD_REQUEST,
  492. /* This response means the client must authenticate itself
  493. * to get the requested response.
  494. */
  495. HTTPD_401_UNAUTHORIZED,
  496. /* The client does not have access rights to the content,
  497. * so the server is refusing to give the requested resource.
  498. * Unlike 401, the client's identity is known to the server.
  499. */
  500. HTTPD_403_FORBIDDEN,
  501. /* When requested URI is not found */
  502. HTTPD_404_NOT_FOUND,
  503. /* When URI found, but method has no handler registered */
  504. HTTPD_405_METHOD_NOT_ALLOWED,
  505. /* Intended for recv timeout. Presently it's being sent
  506. * for other recv errors as well. Client should expect the
  507. * server to immediately close the connection after
  508. * responding with this.
  509. */
  510. HTTPD_408_REQ_TIMEOUT,
  511. /* Intended for responding to chunked encoding, which is
  512. * not supported currently. Though unhandled http_parser
  513. * callback for chunked request returns "400 Bad Request"
  514. */
  515. HTTPD_411_LENGTH_REQUIRED,
  516. /* URI length greater than CONFIG_HTTPD_MAX_URI_LEN */
  517. HTTPD_414_URI_TOO_LONG,
  518. /* Headers section larger than CONFIG_HTTPD_MAX_REQ_HDR_LEN */
  519. HTTPD_431_REQ_HDR_FIELDS_TOO_LARGE,
  520. /* Used internally for retrieving the total count of errors */
  521. HTTPD_ERR_CODE_MAX
  522. } httpd_err_code_t;
  523. /**
  524. * @brief Function prototype for HTTP error handling.
  525. *
  526. * This function is executed upon HTTP errors generated during
  527. * internal processing of an HTTP request. This is used to override
  528. * the default behavior on error, which is to send HTTP error response
  529. * and close the underlying socket.
  530. *
  531. * @note
  532. * - If implemented, the server will not automatically send out HTTP
  533. * error response codes, therefore, httpd_resp_send_err() must be
  534. * invoked inside this function if user wishes to generate HTTP
  535. * error responses.
  536. * - When invoked, the validity of `uri`, `method`, `content_len`
  537. * and `user_ctx` fields of the httpd_req_t parameter is not
  538. * guaranteed as the HTTP request may be partially received/parsed.
  539. * - The function must return ESP_OK if underlying socket needs to
  540. * be kept open. Any other value will ensure that the socket is
  541. * closed. The return value is ignored when error is of type
  542. * `HTTPD_500_INTERNAL_SERVER_ERROR` and the socket closed anyway.
  543. *
  544. * @param[in] req HTTP request for which the error needs to be handled
  545. * @param[in] error Error type
  546. *
  547. * @return
  548. * - ESP_OK : error handled successful
  549. * - ESP_FAIL : failure indicates that the underlying socket needs to be closed
  550. */
  551. typedef esp_err_t (*httpd_err_handler_func_t)(httpd_req_t *req,
  552. httpd_err_code_t error);
  553. /**
  554. * @brief Function for registering HTTP error handlers
  555. *
  556. * This function maps a handler function to any supported error code
  557. * given by `httpd_err_code_t`. See prototype `httpd_err_handler_func_t`
  558. * above for details.
  559. *
  560. * @param[in] handle HTTP server handle
  561. * @param[in] error Error type
  562. * @param[in] handler_fn User implemented handler function
  563. * (Pass NULL to unset any previously set handler)
  564. *
  565. * @return
  566. * - ESP_OK : handler registered successfully
  567. * - ESP_ERR_INVALID_ARG : invalid error code or server handle
  568. */
  569. esp_err_t httpd_register_err_handler(httpd_handle_t handle,
  570. httpd_err_code_t error,
  571. httpd_err_handler_func_t handler_fn);
  572. /** End of HTTP Error
  573. * @}
  574. */
  575. /* ************** Group: TX/RX ************** */
  576. /** @name TX / RX
  577. * Prototype for HTTPDs low-level send/recv functions
  578. * @{
  579. */
  580. #define HTTPD_SOCK_ERR_FAIL -1
  581. #define HTTPD_SOCK_ERR_INVALID -2
  582. #define HTTPD_SOCK_ERR_TIMEOUT -3
  583. /**
  584. * @brief Prototype for HTTPDs low-level send function
  585. *
  586. * @note User specified send function must handle errors internally,
  587. * depending upon the set value of errno, and return specific
  588. * HTTPD_SOCK_ERR_ codes, which will eventually be conveyed as
  589. * return value of httpd_send() function
  590. *
  591. * @param[in] hd server instance
  592. * @param[in] sockfd session socket file descriptor
  593. * @param[in] buf buffer with bytes to send
  594. * @param[in] buf_len data size
  595. * @param[in] flags flags for the send() function
  596. * @return
  597. * - Bytes : The number of bytes sent successfully
  598. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  599. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
  600. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
  601. */
  602. typedef int (*httpd_send_func_t)(httpd_handle_t hd, int sockfd, const char *buf, size_t buf_len, int flags);
  603. /**
  604. * @brief Prototype for HTTPDs low-level recv function
  605. *
  606. * @note User specified recv function must handle errors internally,
  607. * depending upon the set value of errno, and return specific
  608. * HTTPD_SOCK_ERR_ codes, which will eventually be conveyed as
  609. * return value of httpd_req_recv() function
  610. *
  611. * @param[in] hd server instance
  612. * @param[in] sockfd session socket file descriptor
  613. * @param[in] buf buffer with bytes to send
  614. * @param[in] buf_len data size
  615. * @param[in] flags flags for the send() function
  616. * @return
  617. * - Bytes : The number of bytes received successfully
  618. * - 0 : Buffer length parameter is zero / connection closed by peer
  619. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  620. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
  621. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
  622. */
  623. typedef int (*httpd_recv_func_t)(httpd_handle_t hd, int sockfd, char *buf, size_t buf_len, int flags);
  624. /**
  625. * @brief Prototype for HTTPDs low-level "get pending bytes" function
  626. *
  627. * @note User specified pending function must handle errors internally,
  628. * depending upon the set value of errno, and return specific
  629. * HTTPD_SOCK_ERR_ codes, which will be handled accordingly in
  630. * the server task.
  631. *
  632. * @param[in] hd server instance
  633. * @param[in] sockfd session socket file descriptor
  634. * @return
  635. * - Bytes : The number of bytes waiting to be received
  636. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  637. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket pending()
  638. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket pending()
  639. */
  640. typedef int (*httpd_pending_func_t)(httpd_handle_t hd, int sockfd);
  641. /** End of TX / RX
  642. * @}
  643. */
  644. /* ************** Group: Request/Response ************** */
  645. /** @name Request / Response
  646. * APIs related to the data send/receive by URI handlers.
  647. * These APIs are supposed to be called only from the context of
  648. * a URI handler where httpd_req_t* request pointer is valid.
  649. * @{
  650. */
  651. /**
  652. * @brief Override web server's receive function (by session FD)
  653. *
  654. * This function overrides the web server's receive function. This same function is
  655. * used to read HTTP request packets.
  656. *
  657. * @note This API is supposed to be called either from the context of
  658. * - an http session APIs where sockfd is a valid parameter
  659. * - a URI handler where sockfd is obtained using httpd_req_to_sockfd()
  660. *
  661. * @param[in] hd HTTPD instance handle
  662. * @param[in] sockfd Session socket FD
  663. * @param[in] recv_func The receive function to be set for this session
  664. *
  665. * @return
  666. * - ESP_OK : On successfully registering override
  667. * - ESP_ERR_INVALID_ARG : Null arguments
  668. */
  669. esp_err_t httpd_sess_set_recv_override(httpd_handle_t hd, int sockfd, httpd_recv_func_t recv_func);
  670. /**
  671. * @brief Override web server's send function (by session FD)
  672. *
  673. * This function overrides the web server's send function. This same function is
  674. * used to send out any response to any HTTP request.
  675. *
  676. * @note This API is supposed to be called either from the context of
  677. * - an http session APIs where sockfd is a valid parameter
  678. * - a URI handler where sockfd is obtained using httpd_req_to_sockfd()
  679. *
  680. * @param[in] hd HTTPD instance handle
  681. * @param[in] sockfd Session socket FD
  682. * @param[in] send_func The send function to be set for this session
  683. *
  684. * @return
  685. * - ESP_OK : On successfully registering override
  686. * - ESP_ERR_INVALID_ARG : Null arguments
  687. */
  688. esp_err_t httpd_sess_set_send_override(httpd_handle_t hd, int sockfd, httpd_send_func_t send_func);
  689. /**
  690. * @brief Override web server's pending function (by session FD)
  691. *
  692. * This function overrides the web server's pending function. This function is
  693. * used to test for pending bytes in a socket.
  694. *
  695. * @note This API is supposed to be called either from the context of
  696. * - an http session APIs where sockfd is a valid parameter
  697. * - a URI handler where sockfd is obtained using httpd_req_to_sockfd()
  698. *
  699. * @param[in] hd HTTPD instance handle
  700. * @param[in] sockfd Session socket FD
  701. * @param[in] pending_func The receive function to be set for this session
  702. *
  703. * @return
  704. * - ESP_OK : On successfully registering override
  705. * - ESP_ERR_INVALID_ARG : Null arguments
  706. */
  707. esp_err_t httpd_sess_set_pending_override(httpd_handle_t hd, int sockfd, httpd_pending_func_t pending_func);
  708. /**
  709. * @brief Get the Socket Descriptor from the HTTP request
  710. *
  711. * This API will return the socket descriptor of the session for
  712. * which URI handler was executed on reception of HTTP request.
  713. * This is useful when user wants to call functions that require
  714. * session socket fd, from within a URI handler, ie. :
  715. * httpd_sess_get_ctx(),
  716. * httpd_sess_trigger_close(),
  717. * httpd_sess_update_lru_counter().
  718. *
  719. * @note This API is supposed to be called only from the context of
  720. * a URI handler where httpd_req_t* request pointer is valid.
  721. *
  722. * @param[in] r The request whose socket descriptor should be found
  723. *
  724. * @return
  725. * - Socket descriptor : The socket descriptor for this request
  726. * - -1 : Invalid/NULL request pointer
  727. */
  728. int httpd_req_to_sockfd(httpd_req_t *r);
  729. /**
  730. * @brief API to read content data from the HTTP request
  731. *
  732. * This API will read HTTP content data from the HTTP request into
  733. * provided buffer. Use content_len provided in httpd_req_t structure
  734. * to know the length of data to be fetched. If content_len is too
  735. * large for the buffer then user may have to make multiple calls to
  736. * this function, each time fetching 'buf_len' number of bytes,
  737. * while the pointer to content data is incremented internally by
  738. * the same number.
  739. *
  740. * @note
  741. * - This API is supposed to be called only from the context of
  742. * a URI handler where httpd_req_t* request pointer is valid.
  743. * - If an error is returned, the URI handler must further return an error.
  744. * This will ensure that the erroneous socket is closed and cleaned up by
  745. * the web server.
  746. * - Presently Chunked Encoding is not supported
  747. *
  748. * @param[in] r The request being responded to
  749. * @param[in] buf Pointer to a buffer that the data will be read into
  750. * @param[in] buf_len Length of the buffer
  751. *
  752. * @return
  753. * - Bytes : Number of bytes read into the buffer successfully
  754. * - 0 : Buffer length parameter is zero / connection closed by peer
  755. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  756. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
  757. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
  758. */
  759. int httpd_req_recv(httpd_req_t *r, char *buf, size_t buf_len);
  760. /**
  761. * @brief Search for a field in request headers and
  762. * return the string length of it's value
  763. *
  764. * @note
  765. * - This API is supposed to be called only from the context of
  766. * a URI handler where httpd_req_t* request pointer is valid.
  767. * - Once httpd_resp_send() API is called all request headers
  768. * are purged, so request headers need be copied into separate
  769. * buffers if they are required later.
  770. *
  771. * @param[in] r The request being responded to
  772. * @param[in] field The header field to be searched in the request
  773. *
  774. * @return
  775. * - Length : If field is found in the request URL
  776. * - Zero : Field not found / Invalid request / Null arguments
  777. */
  778. size_t httpd_req_get_hdr_value_len(httpd_req_t *r, const char *field);
  779. /**
  780. * @brief Get the value string of a field from the request headers
  781. *
  782. * @note
  783. * - This API is supposed to be called only from the context of
  784. * a URI handler where httpd_req_t* request pointer is valid.
  785. * - Once httpd_resp_send() API is called all request headers
  786. * are purged, so request headers need be copied into separate
  787. * buffers if they are required later.
  788. * - If output size is greater than input, then the value is truncated,
  789. * accompanied by truncation error as return value.
  790. * - Use httpd_req_get_hdr_value_len() to know the right buffer length
  791. *
  792. * @param[in] r The request being responded to
  793. * @param[in] field The field to be searched in the header
  794. * @param[out] val Pointer to the buffer into which the value will be copied if the field is found
  795. * @param[in] val_size Size of the user buffer "val"
  796. *
  797. * @return
  798. * - ESP_OK : Field found in the request header and value string copied
  799. * - ESP_ERR_NOT_FOUND : Key not found
  800. * - ESP_ERR_INVALID_ARG : Null arguments
  801. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer
  802. * - ESP_ERR_HTTPD_RESULT_TRUNC : Value string truncated
  803. */
  804. esp_err_t httpd_req_get_hdr_value_str(httpd_req_t *r, const char *field, char *val, size_t val_size);
  805. /**
  806. * @brief Get Query string length from the request URL
  807. *
  808. * @note This API is supposed to be called only from the context of
  809. * a URI handler where httpd_req_t* request pointer is valid
  810. *
  811. * @param[in] r The request being responded to
  812. *
  813. * @return
  814. * - Length : Query is found in the request URL
  815. * - Zero : Query not found / Null arguments / Invalid request
  816. */
  817. size_t httpd_req_get_url_query_len(httpd_req_t *r);
  818. /**
  819. * @brief Get Query string from the request URL
  820. *
  821. * @note
  822. * - Presently, the user can fetch the full URL query string, but decoding
  823. * will have to be performed by the user. Request headers can be read using
  824. * httpd_req_get_hdr_value_str() to know the 'Content-Type' (eg. Content-Type:
  825. * application/x-www-form-urlencoded) and then the appropriate decoding
  826. * algorithm needs to be applied.
  827. * - This API is supposed to be called only from the context of
  828. * a URI handler where httpd_req_t* request pointer is valid
  829. * - If output size is greater than input, then the value is truncated,
  830. * accompanied by truncation error as return value
  831. * - Prior to calling this function, one can use httpd_req_get_url_query_len()
  832. * to know the query string length beforehand and hence allocate the buffer
  833. * of right size (usually query string length + 1 for null termination)
  834. * for storing the query string
  835. *
  836. * @param[in] r The request being responded to
  837. * @param[out] buf Pointer to the buffer into which the query string will be copied (if found)
  838. * @param[in] buf_len Length of output buffer
  839. *
  840. * @return
  841. * - ESP_OK : Query is found in the request URL and copied to buffer
  842. * - ESP_ERR_NOT_FOUND : Query not found
  843. * - ESP_ERR_INVALID_ARG : Null arguments
  844. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer
  845. * - ESP_ERR_HTTPD_RESULT_TRUNC : Query string truncated
  846. */
  847. esp_err_t httpd_req_get_url_query_str(httpd_req_t *r, char *buf, size_t buf_len);
  848. /**
  849. * @brief Helper function to get a URL query tag from a query
  850. * string of the type param1=val1&param2=val2
  851. *
  852. * @note
  853. * - The components of URL query string (keys and values) are not URLdecoded.
  854. * The user must check for 'Content-Type' field in the request headers and
  855. * then depending upon the specified encoding (URLencoded or otherwise) apply
  856. * the appropriate decoding algorithm.
  857. * - If actual value size is greater than val_size, then the value is truncated,
  858. * accompanied by truncation error as return value.
  859. *
  860. * @param[in] qry Pointer to query string
  861. * @param[in] key The key to be searched in the query string
  862. * @param[out] val Pointer to the buffer into which the value will be copied if the key is found
  863. * @param[in] val_size Size of the user buffer "val"
  864. *
  865. * @return
  866. * - ESP_OK : Key is found in the URL query string and copied to buffer
  867. * - ESP_ERR_NOT_FOUND : Key not found
  868. * - ESP_ERR_INVALID_ARG : Null arguments
  869. * - ESP_ERR_HTTPD_RESULT_TRUNC : Value string truncated
  870. */
  871. esp_err_t httpd_query_key_value(const char *qry, const char *key, char *val, size_t val_size);
  872. /**
  873. * @brief Test if a URI matches the given wildcard template.
  874. *
  875. * Template may end with "?" to make the previous character optional (typically a slash),
  876. * "*" for a wildcard match, and "?*" to make the previous character optional, and if present,
  877. * allow anything to follow.
  878. *
  879. * Example:
  880. * - * matches everything
  881. * - /foo/? matches /foo and /foo/
  882. * - /foo/\* (sans the backslash) matches /foo/ and /foo/bar, but not /foo or /fo
  883. * - /foo/?* or /foo/\*? (sans the backslash) matches /foo/, /foo/bar, and also /foo, but not /foox or /fo
  884. *
  885. * The special characters "?" and "*" anywhere else in the template will be taken literally.
  886. *
  887. * @param[in] uri_template URI template (pattern)
  888. * @param[in] uri_to_match URI to be matched
  889. * @param[in] match_upto how many characters of the URI buffer to test
  890. * (there may be trailing query string etc.)
  891. *
  892. * @return true if a match was found
  893. */
  894. bool httpd_uri_match_wildcard(const char *uri_template, const char *uri_to_match, size_t match_upto);
  895. /**
  896. * @brief API to send a complete HTTP response.
  897. *
  898. * This API will send the data as an HTTP response to the request.
  899. * This assumes that you have the entire response ready in a single
  900. * buffer. If you wish to send response in incremental chunks use
  901. * httpd_resp_send_chunk() instead.
  902. *
  903. * If no status code and content-type were set, by default this
  904. * will send 200 OK status code and content type as text/html.
  905. * You may call the following functions before this API to configure
  906. * the response headers :
  907. * httpd_resp_set_status() - for setting the HTTP status string,
  908. * httpd_resp_set_type() - for setting the Content Type,
  909. * httpd_resp_set_hdr() - for appending any additional field
  910. * value entries in the response header
  911. *
  912. * @note
  913. * - This API is supposed to be called only from the context of
  914. * a URI handler where httpd_req_t* request pointer is valid.
  915. * - Once this API is called, the request has been responded to.
  916. * - No additional data can then be sent for the request.
  917. * - Once this API is called, all request headers are purged, so
  918. * request headers need be copied into separate buffers if
  919. * they are required later.
  920. *
  921. * @param[in] r The request being responded to
  922. * @param[in] buf Buffer from where the content is to be fetched
  923. * @param[in] buf_len Length of the buffer, HTTPD_RESP_USE_STRLEN to use strlen()
  924. *
  925. * @return
  926. * - ESP_OK : On successfully sending the response packet
  927. * - ESP_ERR_INVALID_ARG : Null request pointer
  928. * - ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
  929. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  930. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
  931. */
  932. esp_err_t httpd_resp_send(httpd_req_t *r, const char *buf, ssize_t buf_len);
  933. /**
  934. * @brief API to send one HTTP chunk
  935. *
  936. * This API will send the data as an HTTP response to the
  937. * request. This API will use chunked-encoding and send the response
  938. * in the form of chunks. If you have the entire response contained in
  939. * a single buffer, please use httpd_resp_send() instead.
  940. *
  941. * If no status code and content-type were set, by default this will
  942. * send 200 OK status code and content type as text/html. You may
  943. * call the following functions before this API to configure the
  944. * response headers
  945. * httpd_resp_set_status() - for setting the HTTP status string,
  946. * httpd_resp_set_type() - for setting the Content Type,
  947. * httpd_resp_set_hdr() - for appending any additional field
  948. * value entries in the response header
  949. *
  950. * @note
  951. * - This API is supposed to be called only from the context of
  952. * a URI handler where httpd_req_t* request pointer is valid.
  953. * - When you are finished sending all your chunks, you must call
  954. * this function with buf_len as 0.
  955. * - Once this API is called, all request headers are purged, so
  956. * request headers need be copied into separate buffers if they
  957. * are required later.
  958. *
  959. * @param[in] r The request being responded to
  960. * @param[in] buf Pointer to a buffer that stores the data
  961. * @param[in] buf_len Length of the buffer, HTTPD_RESP_USE_STRLEN to use strlen()
  962. *
  963. * @return
  964. * - ESP_OK : On successfully sending the response packet chunk
  965. * - ESP_ERR_INVALID_ARG : Null request pointer
  966. * - ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
  967. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  968. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  969. */
  970. esp_err_t httpd_resp_send_chunk(httpd_req_t *r, const char *buf, ssize_t buf_len);
  971. /**
  972. * @brief API to send a complete string as HTTP response.
  973. *
  974. * This API simply calls http_resp_send with buffer length
  975. * set to string length assuming the buffer contains a null
  976. * terminated string
  977. *
  978. * @param[in] r The request being responded to
  979. * @param[in] str String to be sent as response body
  980. *
  981. * @return
  982. * - ESP_OK : On successfully sending the response packet
  983. * - ESP_ERR_INVALID_ARG : Null request pointer
  984. * - ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
  985. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  986. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
  987. */
  988. static inline esp_err_t httpd_resp_sendstr(httpd_req_t *r, const char *str) {
  989. return httpd_resp_send(r, str, (str == NULL) ? 0 : HTTPD_RESP_USE_STRLEN);
  990. }
  991. /**
  992. * @brief API to send a string as an HTTP response chunk.
  993. *
  994. * This API simply calls http_resp_send_chunk with buffer length
  995. * set to string length assuming the buffer contains a null
  996. * terminated string
  997. *
  998. * @param[in] r The request being responded to
  999. * @param[in] str String to be sent as response body (NULL to finish response packet)
  1000. *
  1001. * @return
  1002. * - ESP_OK : On successfully sending the response packet
  1003. * - ESP_ERR_INVALID_ARG : Null request pointer
  1004. * - ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
  1005. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1006. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
  1007. */
  1008. static inline esp_err_t httpd_resp_sendstr_chunk(httpd_req_t *r, const char *str) {
  1009. return httpd_resp_send_chunk(r, str, (str == NULL) ? 0 : HTTPD_RESP_USE_STRLEN);
  1010. }
  1011. /* Some commonly used status codes */
  1012. #define HTTPD_200 "200 OK" /*!< HTTP Response 200 */
  1013. #define HTTPD_204 "204 No Content" /*!< HTTP Response 204 */
  1014. #define HTTPD_207 "207 Multi-Status" /*!< HTTP Response 207 */
  1015. #define HTTPD_400 "400 Bad Request" /*!< HTTP Response 400 */
  1016. #define HTTPD_404 "404 Not Found" /*!< HTTP Response 404 */
  1017. #define HTTPD_408 "408 Request Timeout" /*!< HTTP Response 408 */
  1018. #define HTTPD_500 "500 Internal Server Error" /*!< HTTP Response 500 */
  1019. /**
  1020. * @brief API to set the HTTP status code
  1021. *
  1022. * This API sets the status of the HTTP response to the value specified.
  1023. * By default, the '200 OK' response is sent as the response.
  1024. *
  1025. * @note
  1026. * - This API is supposed to be called only from the context of
  1027. * a URI handler where httpd_req_t* request pointer is valid.
  1028. * - This API only sets the status to this value. The status isn't
  1029. * sent out until any of the send APIs is executed.
  1030. * - Make sure that the lifetime of the status string is valid till
  1031. * send function is called.
  1032. *
  1033. * @param[in] r The request being responded to
  1034. * @param[in] status The HTTP status code of this response
  1035. *
  1036. * @return
  1037. * - ESP_OK : On success
  1038. * - ESP_ERR_INVALID_ARG : Null arguments
  1039. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1040. */
  1041. esp_err_t httpd_resp_set_status(httpd_req_t *r, const char *status);
  1042. /* Some commonly used content types */
  1043. #define HTTPD_TYPE_JSON "application/json" /*!< HTTP Content type JSON */
  1044. #define HTTPD_TYPE_TEXT "text/html" /*!< HTTP Content type text/HTML */
  1045. #define HTTPD_TYPE_OCTET "application/octet-stream" /*!< HTTP Content type octext-stream */
  1046. /**
  1047. * @brief API to set the HTTP content type
  1048. *
  1049. * This API sets the 'Content Type' field of the response.
  1050. * The default content type is 'text/html'.
  1051. *
  1052. * @note
  1053. * - This API is supposed to be called only from the context of
  1054. * a URI handler where httpd_req_t* request pointer is valid.
  1055. * - This API only sets the content type to this value. The type
  1056. * isn't sent out until any of the send APIs is executed.
  1057. * - Make sure that the lifetime of the type string is valid till
  1058. * send function is called.
  1059. *
  1060. * @param[in] r The request being responded to
  1061. * @param[in] type The Content Type of the response
  1062. *
  1063. * @return
  1064. * - ESP_OK : On success
  1065. * - ESP_ERR_INVALID_ARG : Null arguments
  1066. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1067. */
  1068. esp_err_t httpd_resp_set_type(httpd_req_t *r, const char *type);
  1069. /**
  1070. * @brief API to append any additional headers
  1071. *
  1072. * This API sets any additional header fields that need to be sent in the response.
  1073. *
  1074. * @note
  1075. * - This API is supposed to be called only from the context of
  1076. * a URI handler where httpd_req_t* request pointer is valid.
  1077. * - The header isn't sent out until any of the send APIs is executed.
  1078. * - The maximum allowed number of additional headers is limited to
  1079. * value of max_resp_headers in config structure.
  1080. * - Make sure that the lifetime of the field value strings are valid till
  1081. * send function is called.
  1082. *
  1083. * @param[in] r The request being responded to
  1084. * @param[in] field The field name of the HTTP header
  1085. * @param[in] value The value of this HTTP header
  1086. *
  1087. * @return
  1088. * - ESP_OK : On successfully appending new header
  1089. * - ESP_ERR_INVALID_ARG : Null arguments
  1090. * - ESP_ERR_HTTPD_RESP_HDR : Total additional headers exceed max allowed
  1091. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1092. */
  1093. esp_err_t httpd_resp_set_hdr(httpd_req_t *r, const char *field, const char *value);
  1094. /**
  1095. * @brief For sending out error code in response to HTTP request.
  1096. *
  1097. * @note
  1098. * - This API is supposed to be called only from the context of
  1099. * a URI handler where httpd_req_t* request pointer is valid.
  1100. * - Once this API is called, all request headers are purged, so
  1101. * request headers need be copied into separate buffers if
  1102. * they are required later.
  1103. * - If you wish to send additional data in the body of the
  1104. * response, please use the lower-level functions directly.
  1105. *
  1106. * @param[in] req Pointer to the HTTP request for which the response needs to be sent
  1107. * @param[in] error Error type to send
  1108. * @param[in] msg Error message string (pass NULL for default message)
  1109. *
  1110. * @return
  1111. * - ESP_OK : On successfully sending the response packet
  1112. * - ESP_ERR_INVALID_ARG : Null arguments
  1113. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1114. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1115. */
  1116. esp_err_t httpd_resp_send_err(httpd_req_t *req, httpd_err_code_t error, const char *msg);
  1117. /**
  1118. * @brief Helper function for HTTP 404
  1119. *
  1120. * Send HTTP 404 message. If you wish to send additional data in the body of the
  1121. * response, please use the lower-level functions directly.
  1122. *
  1123. * @note
  1124. * - This API is supposed to be called only from the context of
  1125. * a URI handler where httpd_req_t* request pointer is valid.
  1126. * - Once this API is called, all request headers are purged, so
  1127. * request headers need be copied into separate buffers if
  1128. * they are required later.
  1129. *
  1130. * @param[in] r The request being responded to
  1131. *
  1132. * @return
  1133. * - ESP_OK : On successfully sending the response packet
  1134. * - ESP_ERR_INVALID_ARG : Null arguments
  1135. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1136. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1137. */
  1138. static inline esp_err_t httpd_resp_send_404(httpd_req_t *r) {
  1139. return httpd_resp_send_err(r, HTTPD_404_NOT_FOUND, NULL);
  1140. }
  1141. /**
  1142. * @brief Helper function for HTTP 408
  1143. *
  1144. * Send HTTP 408 message. If you wish to send additional data in the body of the
  1145. * response, please use the lower-level functions directly.
  1146. *
  1147. * @note
  1148. * - This API is supposed to be called only from the context of
  1149. * a URI handler where httpd_req_t* request pointer is valid.
  1150. * - Once this API is called, all request headers are purged, so
  1151. * request headers need be copied into separate buffers if
  1152. * they are required later.
  1153. *
  1154. * @param[in] r The request being responded to
  1155. *
  1156. * @return
  1157. * - ESP_OK : On successfully sending the response packet
  1158. * - ESP_ERR_INVALID_ARG : Null arguments
  1159. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1160. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1161. */
  1162. static inline esp_err_t httpd_resp_send_408(httpd_req_t *r) {
  1163. return httpd_resp_send_err(r, HTTPD_408_REQ_TIMEOUT, NULL);
  1164. }
  1165. /**
  1166. * @brief Helper function for HTTP 500
  1167. *
  1168. * Send HTTP 500 message. If you wish to send additional data in the body of the
  1169. * response, please use the lower-level functions directly.
  1170. *
  1171. * @note
  1172. * - This API is supposed to be called only from the context of
  1173. * a URI handler where httpd_req_t* request pointer is valid.
  1174. * - Once this API is called, all request headers are purged, so
  1175. * request headers need be copied into separate buffers if
  1176. * they are required later.
  1177. *
  1178. * @param[in] r The request being responded to
  1179. *
  1180. * @return
  1181. * - ESP_OK : On successfully sending the response packet
  1182. * - ESP_ERR_INVALID_ARG : Null arguments
  1183. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1184. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1185. */
  1186. static inline esp_err_t httpd_resp_send_500(httpd_req_t *r) {
  1187. return httpd_resp_send_err(r, HTTPD_500_INTERNAL_SERVER_ERROR, NULL);
  1188. }
  1189. /**
  1190. * @brief Raw HTTP send
  1191. *
  1192. * Call this API if you wish to construct your custom response packet.
  1193. * When using this, all essential header, eg. HTTP version, Status Code,
  1194. * Content Type and Length, Encoding, etc. will have to be constructed
  1195. * manually, and HTTP delimeters (CRLF) will need to be placed correctly
  1196. * for separating sub-sections of the HTTP response packet.
  1197. *
  1198. * If the send override function is set, this API will end up
  1199. * calling that function eventually to send data out.
  1200. *
  1201. * @note
  1202. * - This API is supposed to be called only from the context of
  1203. * a URI handler where httpd_req_t* request pointer is valid.
  1204. * - Unless the response has the correct HTTP structure (which the
  1205. * user must now ensure) it is not guaranteed that it will be
  1206. * recognized by the client. For most cases, you wouldn't have
  1207. * to call this API, but you would rather use either of :
  1208. * httpd_resp_send(),
  1209. * httpd_resp_send_chunk()
  1210. *
  1211. * @param[in] r The request being responded to
  1212. * @param[in] buf Buffer from where the fully constructed packet is to be read
  1213. * @param[in] buf_len Length of the buffer
  1214. *
  1215. * @return
  1216. * - Bytes : Number of bytes that were sent successfully
  1217. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  1218. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
  1219. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
  1220. */
  1221. int httpd_send(httpd_req_t *r, const char *buf, size_t buf_len);
  1222. /**
  1223. * A low level API to send data on a given socket
  1224. *
  1225. * @note This API is not recommended to be used in any request handler.
  1226. * Use this only for advanced use cases, wherein some asynchronous
  1227. * data is to be sent over a socket.
  1228. *
  1229. * This internally calls the default send function, or the function registered by
  1230. * httpd_sess_set_send_override().
  1231. *
  1232. * @param[in] hd server instance
  1233. * @param[in] sockfd session socket file descriptor
  1234. * @param[in] buf buffer with bytes to send
  1235. * @param[in] buf_len data size
  1236. * @param[in] flags flags for the send() function
  1237. * @return
  1238. * - Bytes : The number of bytes sent successfully
  1239. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  1240. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
  1241. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
  1242. */
  1243. int httpd_socket_send(httpd_handle_t hd, int sockfd, const char *buf, size_t buf_len, int flags);
  1244. /**
  1245. * A low level API to receive data from a given socket
  1246. *
  1247. * @note This API is not recommended to be used in any request handler.
  1248. * Use this only for advanced use cases, wherein some asynchronous
  1249. * communication is required.
  1250. *
  1251. * This internally calls the default recv function, or the function registered by
  1252. * httpd_sess_set_recv_override().
  1253. *
  1254. * @param[in] hd server instance
  1255. * @param[in] sockfd session socket file descriptor
  1256. * @param[in] buf buffer with bytes to send
  1257. * @param[in] buf_len data size
  1258. * @param[in] flags flags for the send() function
  1259. * @return
  1260. * - Bytes : The number of bytes received successfully
  1261. * - 0 : Buffer length parameter is zero / connection closed by peer
  1262. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  1263. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
  1264. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
  1265. */
  1266. int httpd_socket_recv(httpd_handle_t hd, int sockfd, char *buf, size_t buf_len, int flags);
  1267. /** End of Request / Response
  1268. * @}
  1269. */
  1270. /* ************** Group: Session ************** */
  1271. /** @name Session
  1272. * Functions for controlling sessions and accessing context data
  1273. * @{
  1274. */
  1275. /**
  1276. * @brief Get session context from socket descriptor
  1277. *
  1278. * Typically if a session context is created, it is available to URI handlers
  1279. * through the httpd_req_t structure. But, there are cases where the web
  1280. * server's send/receive functions may require the context (for example, for
  1281. * accessing keying information etc). Since the send/receive function only have
  1282. * the socket descriptor at their disposal, this API provides them with a way to
  1283. * retrieve the session context.
  1284. *
  1285. * @param[in] handle Handle to server returned by httpd_start
  1286. * @param[in] sockfd The socket descriptor for which the context should be extracted.
  1287. *
  1288. * @return
  1289. * - void* : Pointer to the context associated with this session
  1290. * - NULL : Empty context / Invalid handle / Invalid socket fd
  1291. */
  1292. void *httpd_sess_get_ctx(httpd_handle_t handle, int sockfd);
  1293. /**
  1294. * @brief Set session context by socket descriptor
  1295. *
  1296. * @param[in] handle Handle to server returned by httpd_start
  1297. * @param[in] sockfd The socket descriptor for which the context should be extracted.
  1298. * @param[in] ctx Context object to assign to the session
  1299. * @param[in] free_fn Function that should be called to free the context
  1300. */
  1301. void httpd_sess_set_ctx(httpd_handle_t handle, int sockfd, void *ctx, httpd_free_ctx_fn_t free_fn);
  1302. /**
  1303. * @brief Get session 'transport' context by socket descriptor
  1304. * @see httpd_sess_get_ctx()
  1305. *
  1306. * This context is used by the send/receive functions, for example to manage SSL context.
  1307. *
  1308. * @param[in] handle Handle to server returned by httpd_start
  1309. * @param[in] sockfd The socket descriptor for which the context should be extracted.
  1310. * @return
  1311. * - void* : Pointer to the transport context associated with this session
  1312. * - NULL : Empty context / Invalid handle / Invalid socket fd
  1313. */
  1314. void *httpd_sess_get_transport_ctx(httpd_handle_t handle, int sockfd);
  1315. /**
  1316. * @brief Set session 'transport' context by socket descriptor
  1317. * @see httpd_sess_set_ctx()
  1318. *
  1319. * @param[in] handle Handle to server returned by httpd_start
  1320. * @param[in] sockfd The socket descriptor for which the context should be extracted.
  1321. * @param[in] ctx Transport context object to assign to the session
  1322. * @param[in] free_fn Function that should be called to free the transport context
  1323. */
  1324. void httpd_sess_set_transport_ctx(httpd_handle_t handle, int sockfd, void *ctx, httpd_free_ctx_fn_t free_fn);
  1325. /**
  1326. * @brief Get HTTPD global user context (it was set in the server config struct)
  1327. *
  1328. * @param[in] handle Handle to server returned by httpd_start
  1329. * @return global user context
  1330. */
  1331. void *httpd_get_global_user_ctx(httpd_handle_t handle);
  1332. /**
  1333. * @brief Get HTTPD global transport context (it was set in the server config struct)
  1334. *
  1335. * @param[in] handle Handle to server returned by httpd_start
  1336. * @return global transport context
  1337. */
  1338. void *httpd_get_global_transport_ctx(httpd_handle_t handle);
  1339. /**
  1340. * @brief Trigger an httpd session close externally
  1341. *
  1342. * @note Calling this API is only required in special circumstances wherein
  1343. * some application requires to close an httpd client session asynchronously.
  1344. *
  1345. * @param[in] handle Handle to server returned by httpd_start
  1346. * @param[in] sockfd The socket descriptor of the session to be closed
  1347. *
  1348. * @return
  1349. * - ESP_OK : On successfully initiating closure
  1350. * - ESP_FAIL : Failure to queue work
  1351. * - ESP_ERR_NOT_FOUND : Socket fd not found
  1352. * - ESP_ERR_INVALID_ARG : Null arguments
  1353. */
  1354. esp_err_t httpd_sess_trigger_close(httpd_handle_t handle, int sockfd);
  1355. /**
  1356. * @brief Update LRU counter for a given socket
  1357. *
  1358. * LRU Counters are internally associated with each session to monitor
  1359. * how recently a session exchanged traffic. When LRU purge is enabled,
  1360. * if a client is requesting for connection but maximum number of
  1361. * sockets/sessions is reached, then the session having the earliest
  1362. * LRU counter is closed automatically.
  1363. *
  1364. * Updating the LRU counter manually prevents the socket from being purged
  1365. * due to the Least Recently Used (LRU) logic, even though it might not
  1366. * have received traffic for some time. This is useful when all open
  1367. * sockets/session are frequently exchanging traffic but the user specifically
  1368. * wants one of the sessions to be kept open, irrespective of when it last
  1369. * exchanged a packet.
  1370. *
  1371. * @note Calling this API is only necessary if the LRU Purge Enable option
  1372. * is enabled.
  1373. *
  1374. * @param[in] handle Handle to server returned by httpd_start
  1375. * @param[in] sockfd The socket descriptor of the session for which LRU counter
  1376. * is to be updated
  1377. *
  1378. * @return
  1379. * - ESP_OK : Socket found and LRU counter updated
  1380. * - ESP_ERR_NOT_FOUND : Socket not found
  1381. * - ESP_ERR_INVALID_ARG : Null arguments
  1382. */
  1383. esp_err_t httpd_sess_update_lru_counter(httpd_handle_t handle, int sockfd);
  1384. /**
  1385. * @brief Returns list of current socket descriptors of active sessions
  1386. *
  1387. * @param[in] handle Handle to server returned by httpd_start
  1388. * @param[in,out] fds In: Number of fds allocated in the supplied structure client_fds
  1389. * Out: Number of valid client fds returned in client_fds,
  1390. * @param[out] client_fds Array of client fds
  1391. *
  1392. * @return
  1393. * - ESP_OK : Successfully retrieved session list
  1394. * - ESP_ERR_INVALID_ARG : Wrong arguments or list is longer than allocated
  1395. */
  1396. esp_err_t httpd_get_client_list(httpd_handle_t handle, size_t *fds, int *client_fds);
  1397. /** End of Session
  1398. * @}
  1399. */
  1400. /* ************** Group: Work Queue ************** */
  1401. /** @name Work Queue
  1402. * APIs related to the HTTPD Work Queue
  1403. * @{
  1404. */
  1405. /**
  1406. * @brief Prototype of the HTTPD work function
  1407. * Please refer to httpd_queue_work() for more details.
  1408. * @param[in] arg The arguments for this work function
  1409. */
  1410. typedef void (*httpd_work_fn_t)(void *arg);
  1411. /**
  1412. * @brief Queue execution of a function in HTTPD's context
  1413. *
  1414. * This API queues a work function for asynchronous execution
  1415. *
  1416. * @note Some protocols require that the web server generate some asynchronous data
  1417. * and send it to the persistently opened connection. This facility is for use
  1418. * by such protocols.
  1419. *
  1420. * @param[in] handle Handle to server returned by httpd_start
  1421. * @param[in] work Pointer to the function to be executed in the HTTPD's context
  1422. * @param[in] arg Pointer to the arguments that should be passed to this function
  1423. *
  1424. * @return
  1425. * - ESP_OK : On successfully queueing the work
  1426. * - ESP_FAIL : Failure in ctrl socket
  1427. * - ESP_ERR_INVALID_ARG : Null arguments
  1428. */
  1429. esp_err_t httpd_queue_work(httpd_handle_t handle, httpd_work_fn_t work, void *arg);
  1430. /** End of Group Work Queue
  1431. * @}
  1432. */
  1433. /* ************** Group: WebSocket ************** */
  1434. /** @name WebSocket
  1435. * Functions and structs for WebSocket server
  1436. * @{
  1437. */
  1438. #ifdef CONFIG_HTTPD_WS_SUPPORT
  1439. /**
  1440. * @brief Enum for WebSocket packet types (Opcode in the header)
  1441. * @note Please refer to RFC6455 Section 5.4 for more details
  1442. */
  1443. typedef enum {
  1444. HTTPD_WS_TYPE_CONTINUE = 0x0,
  1445. HTTPD_WS_TYPE_TEXT = 0x1,
  1446. HTTPD_WS_TYPE_BINARY = 0x2,
  1447. HTTPD_WS_TYPE_CLOSE = 0x8,
  1448. HTTPD_WS_TYPE_PING = 0x9,
  1449. HTTPD_WS_TYPE_PONG = 0xA
  1450. } httpd_ws_type_t;
  1451. /**
  1452. * @brief Enum for client info description
  1453. */
  1454. typedef enum {
  1455. HTTPD_WS_CLIENT_INVALID = 0x0,
  1456. HTTPD_WS_CLIENT_HTTP = 0x1,
  1457. HTTPD_WS_CLIENT_WEBSOCKET = 0x2,
  1458. } httpd_ws_client_info_t;
  1459. /**
  1460. * @brief WebSocket frame format
  1461. */
  1462. typedef struct httpd_ws_frame {
  1463. bool final; /*!< Final frame:
  1464. For received frames this field indicates whether the `FIN` flag was set.
  1465. For frames to be transmitted, this field is only used if the `fragmented`
  1466. option is set as well. If `fragmented` is false, the `FIN` flag is set
  1467. by default, marking the ws_frame as a complete/unfragmented message
  1468. (esp_http_server doesn't automatically fragment messages) */
  1469. bool fragmented; /*!< Indication that the frame allocated for transmission is a message fragment,
  1470. so the `FIN` flag is set manually according to the `final` option.
  1471. This flag is never set for received messages */
  1472. httpd_ws_type_t type; /*!< WebSocket frame type */
  1473. uint8_t *payload; /*!< Pre-allocated data buffer */
  1474. size_t len; /*!< Length of the WebSocket data */
  1475. } httpd_ws_frame_t;
  1476. /**
  1477. * @brief Receive and parse a WebSocket frame
  1478. * @param[in] req Current request
  1479. * @param[out] pkt WebSocket packet
  1480. * @param[in] max_len Maximum length for receive
  1481. * @return
  1482. * - ESP_OK : On successful
  1483. * - ESP_FAIL : Socket errors occurs
  1484. * - ESP_ERR_INVALID_STATE : Handshake was already done beforehand
  1485. * - ESP_ERR_INVALID_ARG : Argument is invalid (null or non-WebSocket)
  1486. */
  1487. esp_err_t httpd_ws_recv_frame(httpd_req_t *req, httpd_ws_frame_t *pkt, size_t max_len);
  1488. /**
  1489. * @brief Construct and send a WebSocket frame
  1490. * @param[in] req Current request
  1491. * @param[in] pkt WebSocket frame
  1492. * @return
  1493. * - ESP_OK : On successful
  1494. * - ESP_FAIL : When socket errors occurs
  1495. * - ESP_ERR_INVALID_STATE : Handshake was already done beforehand
  1496. * - ESP_ERR_INVALID_ARG : Argument is invalid (null or non-WebSocket)
  1497. */
  1498. esp_err_t httpd_ws_send_frame(httpd_req_t *req, httpd_ws_frame_t *pkt);
  1499. /**
  1500. * @brief Low level send of a WebSocket frame out of the scope of current request
  1501. * using internally configured httpd send function
  1502. *
  1503. * This API should rarely be called directly, with an exception of asynchronous send using httpd_queue_work.
  1504. *
  1505. * @param[in] hd Server instance data
  1506. * @param[in] fd Socket descriptor for sending data
  1507. * @param[in] frame WebSocket frame
  1508. * @return
  1509. * - ESP_OK : On successful
  1510. * - ESP_FAIL : When socket errors occurs
  1511. * - ESP_ERR_INVALID_STATE : Handshake was already done beforehand
  1512. * - ESP_ERR_INVALID_ARG : Argument is invalid (null or non-WebSocket)
  1513. */
  1514. esp_err_t httpd_ws_send_frame_async(httpd_handle_t hd, int fd, httpd_ws_frame_t *frame);
  1515. /**
  1516. * @brief Checks the supplied socket descriptor if it belongs to any active client
  1517. * of this server instance and if the websoket protocol is active
  1518. *
  1519. * @param[in] hd Server instance data
  1520. * @param[in] fd Socket descriptor
  1521. * @return
  1522. * - HTTPD_WS_CLIENT_INVALID : This fd is not a client of this httpd
  1523. * - HTTPD_WS_CLIENT_HTTP : This fd is an active client, protocol is not WS
  1524. * - HTTPD_WS_CLIENT_WEBSOCKET : This fd is an active client, protocol is WS
  1525. */
  1526. httpd_ws_client_info_t httpd_ws_get_fd_info(httpd_handle_t hd, int fd);
  1527. #endif /* CONFIG_HTTPD_WS_SUPPORT */
  1528. /** End of WebSocket related stuff
  1529. * @}
  1530. */
  1531. #ifdef __cplusplus
  1532. }
  1533. #endif
  1534. #endif /* ! _ESP_HTTP_SERVER_H_ */