Commit Graph

40 Commits

Author SHA1 Message Date
Chip Weinberger
3824eba04d
feat(httpd): add support for asynchronous request handling
This commit adds support for handling multiple requests simultaneously by introducing two new functions: `httpd_req_async_handler_begin()` and `httpd_req_async_handler_complete()`. These functions allow creating an asynchronous copy of a request that can be used on a separate thread and marking the asynchronous request as completed, respectively.

Additionally, a new flag `for_async_req` has been added to the `httpd_sess_t` struct to indicate if a socket is being used for an asynchronous request and should not be purged from the LRU cache.

An example have been added to demonstrate the usage of these new functions.

Closes https://github.com/espressif/esp-idf/issues/10594

Signed-off-by: Harshit Malpani <harshit.malpani@espressif.com>
2023-05-19 10:05:42 +05:30
Harshit Malpani
7c68b67295
esp_http_server: Update to support build for Linux 2023-03-31 16:42:05 +05:30
Harshit Malpani
0885d8542d
esp_http_server: Added support for esp_events 2022-12-19 17:33:37 +05:30
Mahavir Jain
79216c657e
esp_http_server: modify error print for clarifying internal socket usage
Closes https://github.com/espressif/esp-idf/issues/10108
Closes IDFGH-8663
2022-11-15 20:46:35 +05:30
Mahavir Jain
34f3287323
esp_http_server: fix default control port for HTTPS configuration
For simultaneous HTTP and HTTPS server use-case, default configurations
set same control socket port and hence one of the server initialization
fails with an error "error in creating control socket".

This commit modifies default initializers to use different control
socket port in HTTP vs HTTPS server case.

Closes https://github.com/espressif/esp-idf/issues/10160
Closes IDFGH-8719
2022-11-15 20:46:35 +05:30
yuanjianmin
e05d61d075 esp_http_server: Add support to enable TCP keepalive config
Closes https://github.com/espressif/esp-idf/issues/9848
2022-10-31 14:37:05 +08:00
Harshit Malpani
a3fd6d1070
esp_http_server: Add linger in httpd_config_t
Closes: https://github.com/espressif/esp-idf/issues/9514
2022-09-22 10:11:50 +05:30
FlorianR
4db3fd17d9 Clarify when the socket is closed if a custom session closing callback is used
When using a custom session closing callback, the IDF will not close the socket for the user. This might result in the system running out of fds. Without any note on that in the documentation, this is easy to miss.
2021-11-25 17:19:11 +08:00
Martin Valik
1f451a4a77 Added more convenient functions for sending data to websocket 2021-09-16 10:53:29 +02:00
Patryk Krzywdziński
f43e9cdaa7 http: Function to get Cookie value from request.
Closes https://github.com/espressif/esp-idf/pull/7273

Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
2021-07-30 13:23:25 +08:00
Jan Brudny
967e057906 esp-tls, esp_http_client and esp_http_server: update copyright notice 2021-05-31 20:06:09 +08:00
Martin Valik
f221b1655d httpd: remove redundant condition from get_client_list()
Premature return from httpd_uri() was also removed to call uri handler after establishing websocket.
2021-03-04 03:23:57 +00:00
yuanjm
cd521d4ae3 esp_http_server: support dynamic payload len for ws server
Closes https://github.com/espressif/esp-idf/issues/6433
2021-02-24 11:40:34 +00:00
Liu Han
669d9820fc esp_http_server: Add some response error code, such as 401, 403 etc.
Closes https://github.com/espressif/esp-idf/issues/5466
2020-12-09 06:22:01 +00:00
Marius Vikhammer
dcb09bac6a http_server: adds support for setting websocket subprotocol
Adds support for setting support subprotocol per websocket URI
2020-11-13 06:40:51 +00:00
David Cermak
6f3fa81863 http_server: Simplified httpd_get_client_list() to return clients in int array 2020-09-09 08:00:20 +02:00
David Cermak
5e1e5f8be9 http_server: Add a flag to enable using control frames in user handlers 2020-09-09 08:00:20 +02:00
David Cermak
fbf2680427 esp_http_server: Add Websocket API to return list of active clients
Closes https://github.com/espressif/esp-idf/issues/5406
2020-09-09 08:00:20 +02:00
David Cermak
d3801be6d9 esp_http_server: Add httpd_ws_get_fd_info() API to check active WS clients
Added a new API to WebSocket server to test provided socket descriptor if it belongs to active clients for this server and if websocket handshake has been performed

Closes https://github.com/espressif/esp-idf/issues/5602
2020-09-03 20:40:11 +02:00
David Čermák
f8b649baaf Merge branch 'bugfix/ws_server_async_send_fin' into 'master'
http_server example: WebSocket server to set final flag in async messages

Closes IDFGH-3443

See merge request espressif/esp-idf!9251
2020-07-15 05:31:02 +08:00
David Cermak
005f21accc http_server: WebSocket server to set flag in transmitted messages by default
Add logic to set `FIN` flag automatically for transmitted WS frames, but
if `fragmented` option set indicating an expert/manual mode, then the
`FIN` flag is set according to the `final` option.
2020-07-13 14:39:22 +00:00
sU8U7SfkcwTJVH7PjaVmej7D
6673407f98 httpd_resp_send: use HTTPD_RESP_USE_STRLEN when possible 2020-07-13 05:34:56 +00:00
Piyush Shah
24587ccbbf esp_http_server: Expose low level socket send/recv APIs
For some advanced use cases, the low level APIs may be useful.
2020-06-11 01:56:47 +00:00
David Cermak
1b842ce1a8 http_server: websocket server to support async send 2020-03-18 20:24:46 +00:00
Jackson Ming Hu
e983042af2 http_server: adds WebSocket support
This commit adds the WebSocket support for esp_http_server
library. It mainly does:

- Handling WebSocket handshake
  - Parsing HTTP upgrade request
  - Reply the upgrade request
- Receive WebSocket packets
  - Parse header, decode to a struct
  - Unmask payload (if required)
- Send WebSocket frames
- Receive WebSocket frame
- Automatic control frame handling

Merges https://github.com/espressif/esp-idf/pull/4306
Closes https://github.com/espressif/esp-idf/issues/4819
2020-03-18 20:24:46 +00:00
Roland Dobai
612db28b6f Fix error code collision and CI check 2019-08-29 08:14:08 +00:00
Anurag Kar
9c6bec203d HTTP Server : Close new session immediately if open_fn fails
open_fn() was introduced in the context of HTTPS server, as a configurable callback function that is called by the HTTP server, on every newly created socket. It is responsible of allocating resources for per session transport security.

Earlier, if open_fn were to fail, the newly created socket would be closed by the server but the corresponding entry, for the now invalid socket, will remain in the internal socket database until that invalid socket is detected due to error when calling select(). Because of this delayed closing of sockets, the HTTPS server would quickly face shortage of available sessions when a lot of SSL handshake errors are happening (this typically occurs when a browser finds that the server certificate is self signed). This changes in this MR fix this issue by clearing up the socket from internal database, right after open_fn fails.

Closes https://github.com/espressif/esp-idf/issues/3479
2019-05-28 08:49:02 +00:00
Anurag Kar
5e1c19d73d esp_http_server : Minor clarification in httpd_req_get_url_query_str() API documentation
Closes https://github.com/espressif/esp-idf/issues/3374
2019-05-06 14:32:24 +05:30
Gregory Eslinger
7f1047847a HTTP Server: Added ability to select core
The task that runs the HTTP server can now be pinned to a particular core by setting `core_id`
in the HTTP server configuration.  By default, the core is set to `tskNO_AFFINITY`, meaning
it can run on any core.

Merges https://github.com/espressif/esp-idf/pull/3190
2019-03-21 11:22:58 +08:00
Piyush Shah
f28f4016cb esp_http_server: Provide apps an option to let http_server ignore sess_ctx changes
By default, if a URI handler changes the http session context,
the webserver internally clears the older context after the handler
returns. However, if applications want to change this behavior and
manage the allocation/de-allocation/freeing themselves and let the
server handle only the "socket close" case, this commit provides such
an option.
2019-03-05 00:21:03 +05:30
Angus Gratton
19fd436e88 Merge branch 'esp_http_server/lru_counter_for_timestamp' into 'master'
esp_http_server/lru_counter_for_timestamp:Added LRU counter for timer

See merge request idf/esp-idf!4205
2019-02-28 07:04:21 +08:00
Supreet Deshpande
4c8e997289 esp_http_server/lru_counter_for_timestamp:Added LRU counter for timer
Replaced the os timer in http server by LRU counter. The timestamp is
unnecessary for LRU.
2019-02-25 10:08:15 +00:00
Anurag Kar
28412d8cb6 http_server : Added feature for invoking user configurable handlers during server errors
Added APIs :
  * httpd_resp_send_err()        : for sending HTTP error responses for error codes given by httpd_err_code_t. It uses TCP_NODELAY option to ensure that HTTP error responses reach the client before socket is closed.
  * httpd_register_err_handler() : for registering HTTP error handler functions of type httpd_err_handler_func_t.

The default behavior, on encountering errors during processing of HTTP requests, is now to send HTTP error response (if possible) and close the underlying socket. User configurable handlers can be used to override this behavior for each error individually (except for 500 Internal Server Error).

Also fixed some typos.

Closes https://github.com/espressif/esp-idf/issues/3005
2019-02-25 09:13:39 +00:00
Anurag Kar
cfebbae3ef esp_http_server : Remove casual use of 'template' keyword
Closes https://github.com/espressif/esp-idf/issues/2956
2019-01-21 16:13:01 +05:30
Anurag Kar
416c55e7f0 HTTP Server : Add uri_match_fn field in config structure which accepts custom URI matching functions of type httpd_uri_match_func_t and defaults to basic string compare when set to NULL.
Move static uri_matches() function to httpd_uri_match_wildcard() under esp_http_server.h and make it optional.
2019-01-14 08:59:55 +05:30
Anurag Kar
107f52c4fc HTTP Server : Add helper APIs for sending string content
Note : In future consider deprecating usage of -1 for setting
buffer length equal to string length in APIs httpd_resp_send()
and httpd_resp_send_chunk()
2019-01-14 08:36:18 +05:30
Anurag Kar
9a9d18e466 esp_http_server : APIs renamed and context get/set implementations fixed
* http_sess_set_*_override APIs are now the only ones available to set custom recv/send/pending functions
* Fixed side effects to using http_sess_set/get_context inside URI handlers
2018-11-19 04:00:21 +00:00
Anurag Kar
aa6066a197 esp_https_server : Docs and API references fixed 2018-11-19 04:00:21 +00:00
Ondřej Hruška
a10fc02dd9 esp_http_server improvements to allow adding transport layer encryption
Changes:
- renamed `httpd_free_sess_ctx_fn_t` to `httpd_free_ctx_fn_t`
- added a `httpd_handle_t` argument to `httpd_send_func_t` and `httpd_recv_func_t`
- internal function `httpd_sess_get()` is no longer static, as it's used in other
  files besides httpd_sess.c

Bug fixes:
- removed a trailing semicolon from `HTTPD_DEFAULT_CONFIG()`
- fixed issue with failed `select()`, now it automatically closes invalid sockets
  instead of shutting down the entire server

New features:
- `httpd_resp_send()` and `httpd_resp_send_chunk()` now accept -1 as length to use
  `strlen()` internally
- added `httpd_sess_set_ctx()` to accompany `httpd_sess_get_ctx()`
- added a "transport context" to the session structure (next to user context)
- added `httpd_sess_{get,set}_transport_ctx()` to work with this transport context
- added "global user context" and "global transport context" stored in the server
  config (and then the handle); supports a user-provided free_fn
- added a "pending func" to e.g. check for data in the transport layer receive
  buffer
- added functions `httpd_set_sess_{send,recv,pending}_override()` that target
  a session by ID (i.e. not using a request object)
- added `httpd_set_pending_override()`
- added a "open_fn" and "close_fn" - functions called when creating and closing
  a session. These may be used to set up transport layer encryption or some other
  session-wide feature
2018-11-19 04:00:21 +00:00
Anurag Kar
2af9d7e0ed HTTP Server : Added esp_ prefix to http_server component files 2018-10-24 17:32:20 +05:30