esp_http_server.h 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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. /* When requested URI is not found */
  493. HTTPD_404_NOT_FOUND,
  494. /* When URI found, but method has no handler registered */
  495. HTTPD_405_METHOD_NOT_ALLOWED,
  496. /* Intended for recv timeout. Presently it's being sent
  497. * for other recv errors as well. Client should expect the
  498. * server to immediately close the connection after
  499. * responding with this.
  500. */
  501. HTTPD_408_REQ_TIMEOUT,
  502. /* Intended for responding to chunked encoding, which is
  503. * not supported currently. Though unhandled http_parser
  504. * callback for chunked request returns "400 Bad Request"
  505. */
  506. HTTPD_411_LENGTH_REQUIRED,
  507. /* URI length greater than CONFIG_HTTPD_MAX_URI_LEN */
  508. HTTPD_414_URI_TOO_LONG,
  509. /* Headers section larger than CONFIG_HTTPD_MAX_REQ_HDR_LEN */
  510. HTTPD_431_REQ_HDR_FIELDS_TOO_LARGE,
  511. /* Used internally for retrieving the total count of errors */
  512. HTTPD_ERR_CODE_MAX
  513. } httpd_err_code_t;
  514. /**
  515. * @brief Function prototype for HTTP error handling.
  516. *
  517. * This function is executed upon HTTP errors generated during
  518. * internal processing of an HTTP request. This is used to override
  519. * the default behavior on error, which is to send HTTP error response
  520. * and close the underlying socket.
  521. *
  522. * @note
  523. * - If implemented, the server will not automatically send out HTTP
  524. * error response codes, therefore, httpd_resp_send_err() must be
  525. * invoked inside this function if user wishes to generate HTTP
  526. * error responses.
  527. * - When invoked, the validity of `uri`, `method`, `content_len`
  528. * and `user_ctx` fields of the httpd_req_t parameter is not
  529. * guaranteed as the HTTP request may be partially received/parsed.
  530. * - The function must return ESP_OK if underlying socket needs to
  531. * be kept open. Any other value will ensure that the socket is
  532. * closed. The return value is ignored when error is of type
  533. * `HTTPD_500_INTERNAL_SERVER_ERROR` and the socket closed anyway.
  534. *
  535. * @param[in] req HTTP request for which the error needs to be handled
  536. * @param[in] error Error type
  537. *
  538. * @return
  539. * - ESP_OK : error handled successful
  540. * - ESP_FAIL : failure indicates that the underlying socket needs to be closed
  541. */
  542. typedef esp_err_t (*httpd_err_handler_func_t)(httpd_req_t *req,
  543. httpd_err_code_t error);
  544. /**
  545. * @brief Function for registering HTTP error handlers
  546. *
  547. * This function maps a handler function to any supported error code
  548. * given by `httpd_err_code_t`. See prototype `httpd_err_handler_func_t`
  549. * above for details.
  550. *
  551. * @param[in] handle HTTP server handle
  552. * @param[in] error Error type
  553. * @param[in] handler_fn User implemented handler function
  554. * (Pass NULL to unset any previously set handler)
  555. *
  556. * @return
  557. * - ESP_OK : handler registered successfully
  558. * - ESP_ERR_INVALID_ARG : invalid error code or server handle
  559. */
  560. esp_err_t httpd_register_err_handler(httpd_handle_t handle,
  561. httpd_err_code_t error,
  562. httpd_err_handler_func_t handler_fn);
  563. /** End of HTTP Error
  564. * @}
  565. */
  566. /* ************** Group: TX/RX ************** */
  567. /** @name TX / RX
  568. * Prototype for HTTPDs low-level send/recv functions
  569. * @{
  570. */
  571. #define HTTPD_SOCK_ERR_FAIL -1
  572. #define HTTPD_SOCK_ERR_INVALID -2
  573. #define HTTPD_SOCK_ERR_TIMEOUT -3
  574. /**
  575. * @brief Prototype for HTTPDs low-level send function
  576. *
  577. * @note User specified send function must handle errors internally,
  578. * depending upon the set value of errno, and return specific
  579. * HTTPD_SOCK_ERR_ codes, which will eventually be conveyed as
  580. * return value of httpd_send() function
  581. *
  582. * @param[in] hd server instance
  583. * @param[in] sockfd session socket file descriptor
  584. * @param[in] buf buffer with bytes to send
  585. * @param[in] buf_len data size
  586. * @param[in] flags flags for the send() function
  587. * @return
  588. * - Bytes : The number of bytes sent successfully
  589. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  590. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
  591. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
  592. */
  593. typedef int (*httpd_send_func_t)(httpd_handle_t hd, int sockfd, const char *buf, size_t buf_len, int flags);
  594. /**
  595. * @brief Prototype for HTTPDs low-level recv function
  596. *
  597. * @note User specified recv function must handle errors internally,
  598. * depending upon the set value of errno, and return specific
  599. * HTTPD_SOCK_ERR_ codes, which will eventually be conveyed as
  600. * return value of httpd_req_recv() function
  601. *
  602. * @param[in] hd server instance
  603. * @param[in] sockfd session socket file descriptor
  604. * @param[in] buf buffer with bytes to send
  605. * @param[in] buf_len data size
  606. * @param[in] flags flags for the send() function
  607. * @return
  608. * - Bytes : The number of bytes received successfully
  609. * - 0 : Buffer length parameter is zero / connection closed by peer
  610. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  611. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
  612. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
  613. */
  614. typedef int (*httpd_recv_func_t)(httpd_handle_t hd, int sockfd, char *buf, size_t buf_len, int flags);
  615. /**
  616. * @brief Prototype for HTTPDs low-level "get pending bytes" function
  617. *
  618. * @note User specified pending function must handle errors internally,
  619. * depending upon the set value of errno, and return specific
  620. * HTTPD_SOCK_ERR_ codes, which will be handled accordingly in
  621. * the server task.
  622. *
  623. * @param[in] hd server instance
  624. * @param[in] sockfd session socket file descriptor
  625. * @return
  626. * - Bytes : The number of bytes waiting to be received
  627. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  628. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket pending()
  629. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket pending()
  630. */
  631. typedef int (*httpd_pending_func_t)(httpd_handle_t hd, int sockfd);
  632. /** End of TX / RX
  633. * @}
  634. */
  635. /* ************** Group: Request/Response ************** */
  636. /** @name Request / Response
  637. * APIs related to the data send/receive by URI handlers.
  638. * These APIs are supposed to be called only from the context of
  639. * a URI handler where httpd_req_t* request pointer is valid.
  640. * @{
  641. */
  642. /**
  643. * @brief Override web server's receive function (by session FD)
  644. *
  645. * This function overrides the web server's receive function. This same function is
  646. * used to read HTTP request packets.
  647. *
  648. * @note This API is supposed to be called either from the context of
  649. * - an http session APIs where sockfd is a valid parameter
  650. * - a URI handler where sockfd is obtained using httpd_req_to_sockfd()
  651. *
  652. * @param[in] hd HTTPD instance handle
  653. * @param[in] sockfd Session socket FD
  654. * @param[in] recv_func The receive function to be set for this session
  655. *
  656. * @return
  657. * - ESP_OK : On successfully registering override
  658. * - ESP_ERR_INVALID_ARG : Null arguments
  659. */
  660. esp_err_t httpd_sess_set_recv_override(httpd_handle_t hd, int sockfd, httpd_recv_func_t recv_func);
  661. /**
  662. * @brief Override web server's send function (by session FD)
  663. *
  664. * This function overrides the web server's send function. This same function is
  665. * used to send out any response to any HTTP request.
  666. *
  667. * @note This API is supposed to be called either from the context of
  668. * - an http session APIs where sockfd is a valid parameter
  669. * - a URI handler where sockfd is obtained using httpd_req_to_sockfd()
  670. *
  671. * @param[in] hd HTTPD instance handle
  672. * @param[in] sockfd Session socket FD
  673. * @param[in] send_func The send function to be set for this session
  674. *
  675. * @return
  676. * - ESP_OK : On successfully registering override
  677. * - ESP_ERR_INVALID_ARG : Null arguments
  678. */
  679. esp_err_t httpd_sess_set_send_override(httpd_handle_t hd, int sockfd, httpd_send_func_t send_func);
  680. /**
  681. * @brief Override web server's pending function (by session FD)
  682. *
  683. * This function overrides the web server's pending function. This function is
  684. * used to test for pending bytes in a socket.
  685. *
  686. * @note This API is supposed to be called either from the context of
  687. * - an http session APIs where sockfd is a valid parameter
  688. * - a URI handler where sockfd is obtained using httpd_req_to_sockfd()
  689. *
  690. * @param[in] hd HTTPD instance handle
  691. * @param[in] sockfd Session socket FD
  692. * @param[in] pending_func The receive function to be set for this session
  693. *
  694. * @return
  695. * - ESP_OK : On successfully registering override
  696. * - ESP_ERR_INVALID_ARG : Null arguments
  697. */
  698. esp_err_t httpd_sess_set_pending_override(httpd_handle_t hd, int sockfd, httpd_pending_func_t pending_func);
  699. /**
  700. * @brief Get the Socket Descriptor from the HTTP request
  701. *
  702. * This API will return the socket descriptor of the session for
  703. * which URI handler was executed on reception of HTTP request.
  704. * This is useful when user wants to call functions that require
  705. * session socket fd, from within a URI handler, ie. :
  706. * httpd_sess_get_ctx(),
  707. * httpd_sess_trigger_close(),
  708. * httpd_sess_update_lru_counter().
  709. *
  710. * @note This API is supposed to be called only from the context of
  711. * a URI handler where httpd_req_t* request pointer is valid.
  712. *
  713. * @param[in] r The request whose socket descriptor should be found
  714. *
  715. * @return
  716. * - Socket descriptor : The socket descriptor for this request
  717. * - -1 : Invalid/NULL request pointer
  718. */
  719. int httpd_req_to_sockfd(httpd_req_t *r);
  720. /**
  721. * @brief API to read content data from the HTTP request
  722. *
  723. * This API will read HTTP content data from the HTTP request into
  724. * provided buffer. Use content_len provided in httpd_req_t structure
  725. * to know the length of data to be fetched. If content_len is too
  726. * large for the buffer then user may have to make multiple calls to
  727. * this function, each time fetching 'buf_len' number of bytes,
  728. * while the pointer to content data is incremented internally by
  729. * the same number.
  730. *
  731. * @note
  732. * - This API is supposed to be called only from the context of
  733. * a URI handler where httpd_req_t* request pointer is valid.
  734. * - If an error is returned, the URI handler must further return an error.
  735. * This will ensure that the erroneous socket is closed and cleaned up by
  736. * the web server.
  737. * - Presently Chunked Encoding is not supported
  738. *
  739. * @param[in] r The request being responded to
  740. * @param[in] buf Pointer to a buffer that the data will be read into
  741. * @param[in] buf_len Length of the buffer
  742. *
  743. * @return
  744. * - Bytes : Number of bytes read into the buffer successfully
  745. * - 0 : Buffer length parameter is zero / connection closed by peer
  746. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  747. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
  748. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
  749. */
  750. int httpd_req_recv(httpd_req_t *r, char *buf, size_t buf_len);
  751. /**
  752. * @brief Search for a field in request headers and
  753. * return the string length of it's value
  754. *
  755. * @note
  756. * - This API is supposed to be called only from the context of
  757. * a URI handler where httpd_req_t* request pointer is valid.
  758. * - Once httpd_resp_send() API is called all request headers
  759. * are purged, so request headers need be copied into separate
  760. * buffers if they are required later.
  761. *
  762. * @param[in] r The request being responded to
  763. * @param[in] field The header field to be searched in the request
  764. *
  765. * @return
  766. * - Length : If field is found in the request URL
  767. * - Zero : Field not found / Invalid request / Null arguments
  768. */
  769. size_t httpd_req_get_hdr_value_len(httpd_req_t *r, const char *field);
  770. /**
  771. * @brief Get the value string of a field from the request headers
  772. *
  773. * @note
  774. * - This API is supposed to be called only from the context of
  775. * a URI handler where httpd_req_t* request pointer is valid.
  776. * - Once httpd_resp_send() API is called all request headers
  777. * are purged, so request headers need be copied into separate
  778. * buffers if they are required later.
  779. * - If output size is greater than input, then the value is truncated,
  780. * accompanied by truncation error as return value.
  781. * - Use httpd_req_get_hdr_value_len() to know the right buffer length
  782. *
  783. * @param[in] r The request being responded to
  784. * @param[in] field The field to be searched in the header
  785. * @param[out] val Pointer to the buffer into which the value will be copied if the field is found
  786. * @param[in] val_size Size of the user buffer "val"
  787. *
  788. * @return
  789. * - ESP_OK : Field found in the request header and value string copied
  790. * - ESP_ERR_NOT_FOUND : Key not found
  791. * - ESP_ERR_INVALID_ARG : Null arguments
  792. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer
  793. * - ESP_ERR_HTTPD_RESULT_TRUNC : Value string truncated
  794. */
  795. esp_err_t httpd_req_get_hdr_value_str(httpd_req_t *r, const char *field, char *val, size_t val_size);
  796. /**
  797. * @brief Get Query string length from the request URL
  798. *
  799. * @note This API is supposed to be called only from the context of
  800. * a URI handler where httpd_req_t* request pointer is valid
  801. *
  802. * @param[in] r The request being responded to
  803. *
  804. * @return
  805. * - Length : Query is found in the request URL
  806. * - Zero : Query not found / Null arguments / Invalid request
  807. */
  808. size_t httpd_req_get_url_query_len(httpd_req_t *r);
  809. /**
  810. * @brief Get Query string from the request URL
  811. *
  812. * @note
  813. * - Presently, the user can fetch the full URL query string, but decoding
  814. * will have to be performed by the user. Request headers can be read using
  815. * httpd_req_get_hdr_value_str() to know the 'Content-Type' (eg. Content-Type:
  816. * application/x-www-form-urlencoded) and then the appropriate decoding
  817. * algorithm needs to be applied.
  818. * - This API is supposed to be called only from the context of
  819. * a URI handler where httpd_req_t* request pointer is valid
  820. * - If output size is greater than input, then the value is truncated,
  821. * accompanied by truncation error as return value
  822. * - Prior to calling this function, one can use httpd_req_get_url_query_len()
  823. * to know the query string length beforehand and hence allocate the buffer
  824. * of right size (usually query string length + 1 for null termination)
  825. * for storing the query string
  826. *
  827. * @param[in] r The request being responded to
  828. * @param[out] buf Pointer to the buffer into which the query string will be copied (if found)
  829. * @param[in] buf_len Length of output buffer
  830. *
  831. * @return
  832. * - ESP_OK : Query is found in the request URL and copied to buffer
  833. * - ESP_ERR_NOT_FOUND : Query not found
  834. * - ESP_ERR_INVALID_ARG : Null arguments
  835. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer
  836. * - ESP_ERR_HTTPD_RESULT_TRUNC : Query string truncated
  837. */
  838. esp_err_t httpd_req_get_url_query_str(httpd_req_t *r, char *buf, size_t buf_len);
  839. /**
  840. * @brief Helper function to get a URL query tag from a query
  841. * string of the type param1=val1&param2=val2
  842. *
  843. * @note
  844. * - The components of URL query string (keys and values) are not URLdecoded.
  845. * The user must check for 'Content-Type' field in the request headers and
  846. * then depending upon the specified encoding (URLencoded or otherwise) apply
  847. * the appropriate decoding algorithm.
  848. * - If actual value size is greater than val_size, then the value is truncated,
  849. * accompanied by truncation error as return value.
  850. *
  851. * @param[in] qry Pointer to query string
  852. * @param[in] key The key to be searched in the query string
  853. * @param[out] val Pointer to the buffer into which the value will be copied if the key is found
  854. * @param[in] val_size Size of the user buffer "val"
  855. *
  856. * @return
  857. * - ESP_OK : Key is found in the URL query string and copied to buffer
  858. * - ESP_ERR_NOT_FOUND : Key not found
  859. * - ESP_ERR_INVALID_ARG : Null arguments
  860. * - ESP_ERR_HTTPD_RESULT_TRUNC : Value string truncated
  861. */
  862. esp_err_t httpd_query_key_value(const char *qry, const char *key, char *val, size_t val_size);
  863. /**
  864. * @brief Test if a URI matches the given wildcard template.
  865. *
  866. * Template may end with "?" to make the previous character optional (typically a slash),
  867. * "*" for a wildcard match, and "?*" to make the previous character optional, and if present,
  868. * allow anything to follow.
  869. *
  870. * Example:
  871. * - * matches everything
  872. * - /foo/? matches /foo and /foo/
  873. * - /foo/\* (sans the backslash) matches /foo/ and /foo/bar, but not /foo or /fo
  874. * - /foo/?* or /foo/\*? (sans the backslash) matches /foo/, /foo/bar, and also /foo, but not /foox or /fo
  875. *
  876. * The special characters "?" and "*" anywhere else in the template will be taken literally.
  877. *
  878. * @param[in] uri_template URI template (pattern)
  879. * @param[in] uri_to_match URI to be matched
  880. * @param[in] match_upto how many characters of the URI buffer to test
  881. * (there may be trailing query string etc.)
  882. *
  883. * @return true if a match was found
  884. */
  885. bool httpd_uri_match_wildcard(const char *uri_template, const char *uri_to_match, size_t match_upto);
  886. /**
  887. * @brief API to send a complete HTTP response.
  888. *
  889. * This API will send the data as an HTTP response to the request.
  890. * This assumes that you have the entire response ready in a single
  891. * buffer. If you wish to send response in incremental chunks use
  892. * httpd_resp_send_chunk() instead.
  893. *
  894. * If no status code and content-type were set, by default this
  895. * will send 200 OK status code and content type as text/html.
  896. * You may call the following functions before this API to configure
  897. * the response headers :
  898. * httpd_resp_set_status() - for setting the HTTP status string,
  899. * httpd_resp_set_type() - for setting the Content Type,
  900. * httpd_resp_set_hdr() - for appending any additional field
  901. * value entries in the response header
  902. *
  903. * @note
  904. * - This API is supposed to be called only from the context of
  905. * a URI handler where httpd_req_t* request pointer is valid.
  906. * - Once this API is called, the request has been responded to.
  907. * - No additional data can then be sent for the request.
  908. * - Once this API is called, all request headers are purged, so
  909. * request headers need be copied into separate buffers if
  910. * they are required later.
  911. *
  912. * @param[in] r The request being responded to
  913. * @param[in] buf Buffer from where the content is to be fetched
  914. * @param[in] buf_len Length of the buffer, HTTPD_RESP_USE_STRLEN to use strlen()
  915. *
  916. * @return
  917. * - ESP_OK : On successfully sending the response packet
  918. * - ESP_ERR_INVALID_ARG : Null request pointer
  919. * - ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
  920. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  921. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
  922. */
  923. esp_err_t httpd_resp_send(httpd_req_t *r, const char *buf, ssize_t buf_len);
  924. /**
  925. * @brief API to send one HTTP chunk
  926. *
  927. * This API will send the data as an HTTP response to the
  928. * request. This API will use chunked-encoding and send the response
  929. * in the form of chunks. If you have the entire response contained in
  930. * a single buffer, please use httpd_resp_send() instead.
  931. *
  932. * If no status code and content-type were set, by default this will
  933. * send 200 OK status code and content type as text/html. You may
  934. * call the following functions before this API to configure the
  935. * response headers
  936. * httpd_resp_set_status() - for setting the HTTP status string,
  937. * httpd_resp_set_type() - for setting the Content Type,
  938. * httpd_resp_set_hdr() - for appending any additional field
  939. * value entries in the response header
  940. *
  941. * @note
  942. * - This API is supposed to be called only from the context of
  943. * a URI handler where httpd_req_t* request pointer is valid.
  944. * - When you are finished sending all your chunks, you must call
  945. * this function with buf_len as 0.
  946. * - Once this API is called, all request headers are purged, so
  947. * request headers need be copied into separate buffers if they
  948. * are required later.
  949. *
  950. * @param[in] r The request being responded to
  951. * @param[in] buf Pointer to a buffer that stores the data
  952. * @param[in] buf_len Length of the buffer, HTTPD_RESP_USE_STRLEN to use strlen()
  953. *
  954. * @return
  955. * - ESP_OK : On successfully sending the response packet chunk
  956. * - ESP_ERR_INVALID_ARG : Null request pointer
  957. * - ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
  958. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  959. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  960. */
  961. esp_err_t httpd_resp_send_chunk(httpd_req_t *r, const char *buf, ssize_t buf_len);
  962. /**
  963. * @brief API to send a complete string as HTTP response.
  964. *
  965. * This API simply calls http_resp_send with buffer length
  966. * set to string length assuming the buffer contains a null
  967. * terminated string
  968. *
  969. * @param[in] r The request being responded to
  970. * @param[in] str String to be sent as response body
  971. *
  972. * @return
  973. * - ESP_OK : On successfully sending the response packet
  974. * - ESP_ERR_INVALID_ARG : Null request pointer
  975. * - ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
  976. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  977. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
  978. */
  979. static inline esp_err_t httpd_resp_sendstr(httpd_req_t *r, const char *str) {
  980. return httpd_resp_send(r, str, (str == NULL) ? 0 : HTTPD_RESP_USE_STRLEN);
  981. }
  982. /**
  983. * @brief API to send a string as an HTTP response chunk.
  984. *
  985. * This API simply calls http_resp_send_chunk with buffer length
  986. * set to string length assuming the buffer contains a null
  987. * terminated string
  988. *
  989. * @param[in] r The request being responded to
  990. * @param[in] str String to be sent as response body (NULL to finish response packet)
  991. *
  992. * @return
  993. * - ESP_OK : On successfully sending the response packet
  994. * - ESP_ERR_INVALID_ARG : Null request pointer
  995. * - ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
  996. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  997. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request
  998. */
  999. static inline esp_err_t httpd_resp_sendstr_chunk(httpd_req_t *r, const char *str) {
  1000. return httpd_resp_send_chunk(r, str, (str == NULL) ? 0 : HTTPD_RESP_USE_STRLEN);
  1001. }
  1002. /* Some commonly used status codes */
  1003. #define HTTPD_200 "200 OK" /*!< HTTP Response 200 */
  1004. #define HTTPD_204 "204 No Content" /*!< HTTP Response 204 */
  1005. #define HTTPD_207 "207 Multi-Status" /*!< HTTP Response 207 */
  1006. #define HTTPD_400 "400 Bad Request" /*!< HTTP Response 400 */
  1007. #define HTTPD_404 "404 Not Found" /*!< HTTP Response 404 */
  1008. #define HTTPD_408 "408 Request Timeout" /*!< HTTP Response 408 */
  1009. #define HTTPD_500 "500 Internal Server Error" /*!< HTTP Response 500 */
  1010. /**
  1011. * @brief API to set the HTTP status code
  1012. *
  1013. * This API sets the status of the HTTP response to the value specified.
  1014. * By default, the '200 OK' response is sent as the response.
  1015. *
  1016. * @note
  1017. * - This API is supposed to be called only from the context of
  1018. * a URI handler where httpd_req_t* request pointer is valid.
  1019. * - This API only sets the status to this value. The status isn't
  1020. * sent out until any of the send APIs is executed.
  1021. * - Make sure that the lifetime of the status string is valid till
  1022. * send function is called.
  1023. *
  1024. * @param[in] r The request being responded to
  1025. * @param[in] status The HTTP status code of this response
  1026. *
  1027. * @return
  1028. * - ESP_OK : On success
  1029. * - ESP_ERR_INVALID_ARG : Null arguments
  1030. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1031. */
  1032. esp_err_t httpd_resp_set_status(httpd_req_t *r, const char *status);
  1033. /* Some commonly used content types */
  1034. #define HTTPD_TYPE_JSON "application/json" /*!< HTTP Content type JSON */
  1035. #define HTTPD_TYPE_TEXT "text/html" /*!< HTTP Content type text/HTML */
  1036. #define HTTPD_TYPE_OCTET "application/octet-stream" /*!< HTTP Content type octext-stream */
  1037. /**
  1038. * @brief API to set the HTTP content type
  1039. *
  1040. * This API sets the 'Content Type' field of the response.
  1041. * The default content type is 'text/html'.
  1042. *
  1043. * @note
  1044. * - This API is supposed to be called only from the context of
  1045. * a URI handler where httpd_req_t* request pointer is valid.
  1046. * - This API only sets the content type to this value. The type
  1047. * isn't sent out until any of the send APIs is executed.
  1048. * - Make sure that the lifetime of the type string is valid till
  1049. * send function is called.
  1050. *
  1051. * @param[in] r The request being responded to
  1052. * @param[in] type The Content Type of the response
  1053. *
  1054. * @return
  1055. * - ESP_OK : On success
  1056. * - ESP_ERR_INVALID_ARG : Null arguments
  1057. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1058. */
  1059. esp_err_t httpd_resp_set_type(httpd_req_t *r, const char *type);
  1060. /**
  1061. * @brief API to append any additional headers
  1062. *
  1063. * This API sets any additional header fields that need to be sent in the response.
  1064. *
  1065. * @note
  1066. * - This API is supposed to be called only from the context of
  1067. * a URI handler where httpd_req_t* request pointer is valid.
  1068. * - The header isn't sent out until any of the send APIs is executed.
  1069. * - The maximum allowed number of additional headers is limited to
  1070. * value of max_resp_headers in config structure.
  1071. * - Make sure that the lifetime of the field value strings are valid till
  1072. * send function is called.
  1073. *
  1074. * @param[in] r The request being responded to
  1075. * @param[in] field The field name of the HTTP header
  1076. * @param[in] value The value of this HTTP header
  1077. *
  1078. * @return
  1079. * - ESP_OK : On successfully appending new header
  1080. * - ESP_ERR_INVALID_ARG : Null arguments
  1081. * - ESP_ERR_HTTPD_RESP_HDR : Total additional headers exceed max allowed
  1082. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1083. */
  1084. esp_err_t httpd_resp_set_hdr(httpd_req_t *r, const char *field, const char *value);
  1085. /**
  1086. * @brief For sending out error code in response to HTTP request.
  1087. *
  1088. * @note
  1089. * - This API is supposed to be called only from the context of
  1090. * a URI handler where httpd_req_t* request pointer is valid.
  1091. * - Once this API is called, all request headers are purged, so
  1092. * request headers need be copied into separate buffers if
  1093. * they are required later.
  1094. * - If you wish to send additional data in the body of the
  1095. * response, please use the lower-level functions directly.
  1096. *
  1097. * @param[in] req Pointer to the HTTP request for which the response needs to be sent
  1098. * @param[in] error Error type to send
  1099. * @param[in] msg Error message string (pass NULL for default message)
  1100. *
  1101. * @return
  1102. * - ESP_OK : On successfully sending the response packet
  1103. * - ESP_ERR_INVALID_ARG : Null arguments
  1104. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1105. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1106. */
  1107. esp_err_t httpd_resp_send_err(httpd_req_t *req, httpd_err_code_t error, const char *msg);
  1108. /**
  1109. * @brief Helper function for HTTP 404
  1110. *
  1111. * Send HTTP 404 message. If you wish to send additional data in the body of the
  1112. * response, please use the lower-level functions directly.
  1113. *
  1114. * @note
  1115. * - This API is supposed to be called only from the context of
  1116. * a URI handler where httpd_req_t* request pointer is valid.
  1117. * - Once this API is called, all request headers are purged, so
  1118. * request headers need be copied into separate buffers if
  1119. * they are required later.
  1120. *
  1121. * @param[in] r The request being responded to
  1122. *
  1123. * @return
  1124. * - ESP_OK : On successfully sending the response packet
  1125. * - ESP_ERR_INVALID_ARG : Null arguments
  1126. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1127. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1128. */
  1129. static inline esp_err_t httpd_resp_send_404(httpd_req_t *r) {
  1130. return httpd_resp_send_err(r, HTTPD_404_NOT_FOUND, NULL);
  1131. }
  1132. /**
  1133. * @brief Helper function for HTTP 408
  1134. *
  1135. * Send HTTP 408 message. If you wish to send additional data in the body of the
  1136. * response, please use the lower-level functions directly.
  1137. *
  1138. * @note
  1139. * - This API is supposed to be called only from the context of
  1140. * a URI handler where httpd_req_t* request pointer is valid.
  1141. * - Once this API is called, all request headers are purged, so
  1142. * request headers need be copied into separate buffers if
  1143. * they are required later.
  1144. *
  1145. * @param[in] r The request being responded to
  1146. *
  1147. * @return
  1148. * - ESP_OK : On successfully sending the response packet
  1149. * - ESP_ERR_INVALID_ARG : Null arguments
  1150. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1151. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1152. */
  1153. static inline esp_err_t httpd_resp_send_408(httpd_req_t *r) {
  1154. return httpd_resp_send_err(r, HTTPD_408_REQ_TIMEOUT, NULL);
  1155. }
  1156. /**
  1157. * @brief Helper function for HTTP 500
  1158. *
  1159. * Send HTTP 500 message. If you wish to send additional data in the body of the
  1160. * response, please use the lower-level functions directly.
  1161. *
  1162. * @note
  1163. * - This API is supposed to be called only from the context of
  1164. * a URI handler where httpd_req_t* request pointer is valid.
  1165. * - Once this API is called, all request headers are purged, so
  1166. * request headers need be copied into separate buffers if
  1167. * they are required later.
  1168. *
  1169. * @param[in] r The request being responded to
  1170. *
  1171. * @return
  1172. * - ESP_OK : On successfully sending the response packet
  1173. * - ESP_ERR_INVALID_ARG : Null arguments
  1174. * - ESP_ERR_HTTPD_RESP_SEND : Error in raw send
  1175. * - ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
  1176. */
  1177. static inline esp_err_t httpd_resp_send_500(httpd_req_t *r) {
  1178. return httpd_resp_send_err(r, HTTPD_500_INTERNAL_SERVER_ERROR, NULL);
  1179. }
  1180. /**
  1181. * @brief Raw HTTP send
  1182. *
  1183. * Call this API if you wish to construct your custom response packet.
  1184. * When using this, all essential header, eg. HTTP version, Status Code,
  1185. * Content Type and Length, Encoding, etc. will have to be constructed
  1186. * manually, and HTTP delimeters (CRLF) will need to be placed correctly
  1187. * for separating sub-sections of the HTTP response packet.
  1188. *
  1189. * If the send override function is set, this API will end up
  1190. * calling that function eventually to send data out.
  1191. *
  1192. * @note
  1193. * - This API is supposed to be called only from the context of
  1194. * a URI handler where httpd_req_t* request pointer is valid.
  1195. * - Unless the response has the correct HTTP structure (which the
  1196. * user must now ensure) it is not guaranteed that it will be
  1197. * recognized by the client. For most cases, you wouldn't have
  1198. * to call this API, but you would rather use either of :
  1199. * httpd_resp_send(),
  1200. * httpd_resp_send_chunk()
  1201. *
  1202. * @param[in] r The request being responded to
  1203. * @param[in] buf Buffer from where the fully constructed packet is to be read
  1204. * @param[in] buf_len Length of the buffer
  1205. *
  1206. * @return
  1207. * - Bytes : Number of bytes that were sent successfully
  1208. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  1209. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
  1210. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
  1211. */
  1212. int httpd_send(httpd_req_t *r, const char *buf, size_t buf_len);
  1213. /**
  1214. * A low level API to send data on a given socket
  1215. *
  1216. * @note This API is not recommended to be used in any request handler.
  1217. * Use this only for advanced use cases, wherein some asynchronous
  1218. * data is to be sent over a socket.
  1219. *
  1220. * This internally calls the default send function, or the function registered by
  1221. * httpd_sess_set_send_override().
  1222. *
  1223. * @param[in] hd server instance
  1224. * @param[in] sockfd session socket file descriptor
  1225. * @param[in] buf buffer with bytes to send
  1226. * @param[in] buf_len data size
  1227. * @param[in] flags flags for the send() function
  1228. * @return
  1229. * - Bytes : The number of bytes sent successfully
  1230. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  1231. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket send()
  1232. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket send()
  1233. */
  1234. int httpd_socket_send(httpd_handle_t hd, int sockfd, const char *buf, size_t buf_len, int flags);
  1235. /**
  1236. * A low level API to receive data from a given socket
  1237. *
  1238. * @note This API is not recommended to be used in any request handler.
  1239. * Use this only for advanced use cases, wherein some asynchronous
  1240. * communication is required.
  1241. *
  1242. * This internally calls the default recv function, or the function registered by
  1243. * httpd_sess_set_recv_override().
  1244. *
  1245. * @param[in] hd server instance
  1246. * @param[in] sockfd session socket file descriptor
  1247. * @param[in] buf buffer with bytes to send
  1248. * @param[in] buf_len data size
  1249. * @param[in] flags flags for the send() function
  1250. * @return
  1251. * - Bytes : The number of bytes received successfully
  1252. * - 0 : Buffer length parameter is zero / connection closed by peer
  1253. * - HTTPD_SOCK_ERR_INVALID : Invalid arguments
  1254. * - HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
  1255. * - HTTPD_SOCK_ERR_FAIL : Unrecoverable error while calling socket recv()
  1256. */
  1257. int httpd_socket_recv(httpd_handle_t hd, int sockfd, char *buf, size_t buf_len, int flags);
  1258. /** End of Request / Response
  1259. * @}
  1260. */
  1261. /* ************** Group: Session ************** */
  1262. /** @name Session
  1263. * Functions for controlling sessions and accessing context data
  1264. * @{
  1265. */
  1266. /**
  1267. * @brief Get session context from socket descriptor
  1268. *
  1269. * Typically if a session context is created, it is available to URI handlers
  1270. * through the httpd_req_t structure. But, there are cases where the web
  1271. * server's send/receive functions may require the context (for example, for
  1272. * accessing keying information etc). Since the send/receive function only have
  1273. * the socket descriptor at their disposal, this API provides them with a way to
  1274. * retrieve the session context.
  1275. *
  1276. * @param[in] handle Handle to server returned by httpd_start
  1277. * @param[in] sockfd The socket descriptor for which the context should be extracted.
  1278. *
  1279. * @return
  1280. * - void* : Pointer to the context associated with this session
  1281. * - NULL : Empty context / Invalid handle / Invalid socket fd
  1282. */
  1283. void *httpd_sess_get_ctx(httpd_handle_t handle, int sockfd);
  1284. /**
  1285. * @brief Set session context by socket descriptor
  1286. *
  1287. * @param[in] handle Handle to server returned by httpd_start
  1288. * @param[in] sockfd The socket descriptor for which the context should be extracted.
  1289. * @param[in] ctx Context object to assign to the session
  1290. * @param[in] free_fn Function that should be called to free the context
  1291. */
  1292. void httpd_sess_set_ctx(httpd_handle_t handle, int sockfd, void *ctx, httpd_free_ctx_fn_t free_fn);
  1293. /**
  1294. * @brief Get session 'transport' context by socket descriptor
  1295. * @see httpd_sess_get_ctx()
  1296. *
  1297. * This context is used by the send/receive functions, for example to manage SSL context.
  1298. *
  1299. * @param[in] handle Handle to server returned by httpd_start
  1300. * @param[in] sockfd The socket descriptor for which the context should be extracted.
  1301. * @return
  1302. * - void* : Pointer to the transport context associated with this session
  1303. * - NULL : Empty context / Invalid handle / Invalid socket fd
  1304. */
  1305. void *httpd_sess_get_transport_ctx(httpd_handle_t handle, int sockfd);
  1306. /**
  1307. * @brief Set session 'transport' context by socket descriptor
  1308. * @see httpd_sess_set_ctx()
  1309. *
  1310. * @param[in] handle Handle to server returned by httpd_start
  1311. * @param[in] sockfd The socket descriptor for which the context should be extracted.
  1312. * @param[in] ctx Transport context object to assign to the session
  1313. * @param[in] free_fn Function that should be called to free the transport context
  1314. */
  1315. void httpd_sess_set_transport_ctx(httpd_handle_t handle, int sockfd, void *ctx, httpd_free_ctx_fn_t free_fn);
  1316. /**
  1317. * @brief Get HTTPD global user context (it was set in the server config struct)
  1318. *
  1319. * @param[in] handle Handle to server returned by httpd_start
  1320. * @return global user context
  1321. */
  1322. void *httpd_get_global_user_ctx(httpd_handle_t handle);
  1323. /**
  1324. * @brief Get HTTPD global transport context (it was set in the server config struct)
  1325. *
  1326. * @param[in] handle Handle to server returned by httpd_start
  1327. * @return global transport context
  1328. */
  1329. void *httpd_get_global_transport_ctx(httpd_handle_t handle);
  1330. /**
  1331. * @brief Trigger an httpd session close externally
  1332. *
  1333. * @note Calling this API is only required in special circumstances wherein
  1334. * some application requires to close an httpd client session asynchronously.
  1335. *
  1336. * @param[in] handle Handle to server returned by httpd_start
  1337. * @param[in] sockfd The socket descriptor of the session to be closed
  1338. *
  1339. * @return
  1340. * - ESP_OK : On successfully initiating closure
  1341. * - ESP_FAIL : Failure to queue work
  1342. * - ESP_ERR_NOT_FOUND : Socket fd not found
  1343. * - ESP_ERR_INVALID_ARG : Null arguments
  1344. */
  1345. esp_err_t httpd_sess_trigger_close(httpd_handle_t handle, int sockfd);
  1346. /**
  1347. * @brief Update LRU counter for a given socket
  1348. *
  1349. * LRU Counters are internally associated with each session to monitor
  1350. * how recently a session exchanged traffic. When LRU purge is enabled,
  1351. * if a client is requesting for connection but maximum number of
  1352. * sockets/sessions is reached, then the session having the earliest
  1353. * LRU counter is closed automatically.
  1354. *
  1355. * Updating the LRU counter manually prevents the socket from being purged
  1356. * due to the Least Recently Used (LRU) logic, even though it might not
  1357. * have received traffic for some time. This is useful when all open
  1358. * sockets/session are frequently exchanging traffic but the user specifically
  1359. * wants one of the sessions to be kept open, irrespective of when it last
  1360. * exchanged a packet.
  1361. *
  1362. * @note Calling this API is only necessary if the LRU Purge Enable option
  1363. * is enabled.
  1364. *
  1365. * @param[in] handle Handle to server returned by httpd_start
  1366. * @param[in] sockfd The socket descriptor of the session for which LRU counter
  1367. * is to be updated
  1368. *
  1369. * @return
  1370. * - ESP_OK : Socket found and LRU counter updated
  1371. * - ESP_ERR_NOT_FOUND : Socket not found
  1372. * - ESP_ERR_INVALID_ARG : Null arguments
  1373. */
  1374. esp_err_t httpd_sess_update_lru_counter(httpd_handle_t handle, int sockfd);
  1375. /**
  1376. * @brief Returns list of current socket descriptors of active sessions
  1377. *
  1378. * @param[in] handle Handle to server returned by httpd_start
  1379. * @param[in,out] fds In: Number of fds allocated in the supplied structure client_fds
  1380. * Out: Number of valid client fds returned in client_fds,
  1381. * @param[out] client_fds Array of client fds
  1382. *
  1383. * @return
  1384. * - ESP_OK : Successfully retrieved session list
  1385. * - ESP_ERR_INVALID_ARG : Wrong arguments or list is longer than allocated
  1386. */
  1387. esp_err_t httpd_get_client_list(httpd_handle_t handle, size_t *fds, int *client_fds);
  1388. /** End of Session
  1389. * @}
  1390. */
  1391. /* ************** Group: Work Queue ************** */
  1392. /** @name Work Queue
  1393. * APIs related to the HTTPD Work Queue
  1394. * @{
  1395. */
  1396. /**
  1397. * @brief Prototype of the HTTPD work function
  1398. * Please refer to httpd_queue_work() for more details.
  1399. * @param[in] arg The arguments for this work function
  1400. */
  1401. typedef void (*httpd_work_fn_t)(void *arg);
  1402. /**
  1403. * @brief Queue execution of a function in HTTPD's context
  1404. *
  1405. * This API queues a work function for asynchronous execution
  1406. *
  1407. * @note Some protocols require that the web server generate some asynchronous data
  1408. * and send it to the persistently opened connection. This facility is for use
  1409. * by such protocols.
  1410. *
  1411. * @param[in] handle Handle to server returned by httpd_start
  1412. * @param[in] work Pointer to the function to be executed in the HTTPD's context
  1413. * @param[in] arg Pointer to the arguments that should be passed to this function
  1414. *
  1415. * @return
  1416. * - ESP_OK : On successfully queueing the work
  1417. * - ESP_FAIL : Failure in ctrl socket
  1418. * - ESP_ERR_INVALID_ARG : Null arguments
  1419. */
  1420. esp_err_t httpd_queue_work(httpd_handle_t handle, httpd_work_fn_t work, void *arg);
  1421. /** End of Group Work Queue
  1422. * @}
  1423. */
  1424. /* ************** Group: WebSocket ************** */
  1425. /** @name WebSocket
  1426. * Functions and structs for WebSocket server
  1427. * @{
  1428. */
  1429. #ifdef CONFIG_HTTPD_WS_SUPPORT
  1430. /**
  1431. * @brief Enum for WebSocket packet types (Opcode in the header)
  1432. * @note Please refer to RFC6455 Section 5.4 for more details
  1433. */
  1434. typedef enum {
  1435. HTTPD_WS_TYPE_CONTINUE = 0x0,
  1436. HTTPD_WS_TYPE_TEXT = 0x1,
  1437. HTTPD_WS_TYPE_BINARY = 0x2,
  1438. HTTPD_WS_TYPE_CLOSE = 0x8,
  1439. HTTPD_WS_TYPE_PING = 0x9,
  1440. HTTPD_WS_TYPE_PONG = 0xA
  1441. } httpd_ws_type_t;
  1442. /**
  1443. * @brief Enum for client info description
  1444. */
  1445. typedef enum {
  1446. HTTPD_WS_CLIENT_INVALID = 0x0,
  1447. HTTPD_WS_CLIENT_HTTP = 0x1,
  1448. HTTPD_WS_CLIENT_WEBSOCKET = 0x2,
  1449. } httpd_ws_client_info_t;
  1450. /**
  1451. * @brief WebSocket frame format
  1452. */
  1453. typedef struct httpd_ws_frame {
  1454. bool final; /*!< Final frame:
  1455. For received frames this field indicates whether the `FIN` flag was set.
  1456. For frames to be transmitted, this field is only used if the `fragmented`
  1457. option is set as well. If `fragmented` is false, the `FIN` flag is set
  1458. by default, marking the ws_frame as a complete/unfragmented message
  1459. (esp_http_server doesn't automatically fragment messages) */
  1460. bool fragmented; /*!< Indication that the frame allocated for transmission is a message fragment,
  1461. so the `FIN` flag is set manually according to the `final` option.
  1462. This flag is never set for received messages */
  1463. httpd_ws_type_t type; /*!< WebSocket frame type */
  1464. uint8_t *payload; /*!< Pre-allocated data buffer */
  1465. size_t len; /*!< Length of the WebSocket data */
  1466. } httpd_ws_frame_t;
  1467. /**
  1468. * @brief Receive and parse a WebSocket frame
  1469. * @param[in] req Current request
  1470. * @param[out] pkt WebSocket packet
  1471. * @param[in] max_len Maximum length for receive
  1472. * @return
  1473. * - ESP_OK : On successful
  1474. * - ESP_FAIL : Socket errors occurs
  1475. * - ESP_ERR_INVALID_STATE : Handshake was already done beforehand
  1476. * - ESP_ERR_INVALID_ARG : Argument is invalid (null or non-WebSocket)
  1477. */
  1478. esp_err_t httpd_ws_recv_frame(httpd_req_t *req, httpd_ws_frame_t *pkt, size_t max_len);
  1479. /**
  1480. * @brief Construct and send a WebSocket frame
  1481. * @param[in] req Current request
  1482. * @param[in] pkt WebSocket frame
  1483. * @return
  1484. * - ESP_OK : On successful
  1485. * - ESP_FAIL : When socket errors occurs
  1486. * - ESP_ERR_INVALID_STATE : Handshake was already done beforehand
  1487. * - ESP_ERR_INVALID_ARG : Argument is invalid (null or non-WebSocket)
  1488. */
  1489. esp_err_t httpd_ws_send_frame(httpd_req_t *req, httpd_ws_frame_t *pkt);
  1490. /**
  1491. * @brief Low level send of a WebSocket frame out of the scope of current request
  1492. * using internally configured httpd send function
  1493. *
  1494. * This API should rarely be called directly, with an exception of asynchronous send using httpd_queue_work.
  1495. *
  1496. * @param[in] hd Server instance data
  1497. * @param[in] fd Socket descriptor for sending data
  1498. * @param[in] frame WebSocket frame
  1499. * @return
  1500. * - ESP_OK : On successful
  1501. * - ESP_FAIL : When socket errors occurs
  1502. * - ESP_ERR_INVALID_STATE : Handshake was already done beforehand
  1503. * - ESP_ERR_INVALID_ARG : Argument is invalid (null or non-WebSocket)
  1504. */
  1505. esp_err_t httpd_ws_send_frame_async(httpd_handle_t hd, int fd, httpd_ws_frame_t *frame);
  1506. /**
  1507. * @brief Checks the supplied socket descriptor if it belongs to any active client
  1508. * of this server instance and if the websoket protocol is active
  1509. *
  1510. * @param[in] hd Server instance data
  1511. * @param[in] fd Socket descriptor
  1512. * @return
  1513. * - HTTPD_WS_CLIENT_INVALID : This fd is not a client of this httpd
  1514. * - HTTPD_WS_CLIENT_HTTP : This fd is an active client, protocol is not WS
  1515. * - HTTPD_WS_CLIENT_WEBSOCKET : This fd is an active client, protocol is WS
  1516. */
  1517. httpd_ws_client_info_t httpd_ws_get_fd_info(httpd_handle_t hd, int fd);
  1518. #endif /* CONFIG_HTTPD_WS_SUPPORT */
  1519. /** End of WebSocket related stuff
  1520. * @}
  1521. */
  1522. #ifdef __cplusplus
  1523. }
  1524. #endif
  1525. #endif /* ! _ESP_HTTP_SERVER_H_ */