Commit Graph

126 Commits

Author SHA1 Message Date
Mahavir Jain
af9a194672 Merge branch 'feature/websocket_server_support_close_handle' into 'master'
esp_http_server: Websocket CLOSE frame can support callback function

Closes IDFGH-5785

See merge request espressif/esp-idf!17086
2022-02-16 07:08:57 +00:00
Darian Leung
57fd78f5ba freertos: Remove legacy data types
This commit removes the usage of all legacy FreeRTOS data types that
are exposed via configENABLE_BACKWARD_COMPATIBILITY. Legacy types can
still be used by enabling CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY.
2022-02-09 23:05:45 +08:00
yuanjm
7f1cba9912 esp_http_server: Websocket CLOSE frame can support callback function
Closes https://github.com/espressif/esp-idf/issues/7493
2022-02-09 10:15:36 +08:00
Mahavir Jain
8e94cf2bb1 Add http_parser (new component) dependency 2022-01-11 10:26:25 +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
morris
2e008825a9 Merge branch 'feat/rm_makefiles' into 'master'
Build & config: Remove leftover files from the unsupported make build system

Closes IDF-4273 and IDF-2827

See merge request espressif/esp-idf!15829
2021-11-16 03:44:41 +00:00
Roland Dobai
766aa57084 Build & config: Remove leftover files from the unsupported "make" build system 2021-11-11 15:32:36 +01:00
Dániel Buga
994038e0e9 esp_http_server: Check for failure in stopping http server
In some cases, sending the shutdown signal may fail, which causes `httpd_stop` to wait indefinitely.
This PR adds a check to prevent this infinite loop.

Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>

Closes https://github.com/espressif/esp-idf/pull/7843
2021-11-11 11:43:57 +05:30
Martin Valik
1f451a4a77 Added more convenient functions for sending data to websocket 2021-09-16 10:53:29 +02:00
yuanjm
5db3853c2c esp_http_server: Fix ws server handle length over 1440(MTU) messages incorrectly.
Closes https://github.com/espressif/esp-idf/issues/7457
2021-08-30 14:50:19 +08:00
yuanjm
5bdbfd1d05 Revert "Merge branch 'bugfix/fix_ws_handle_big_messages_error' into 'master'"
This reverts commit d838a11d78, reversing
changes made to 70fd8529e9.
2021-08-30 14:50:19 +08: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
yuanjm
f2a0b48cf9 esp_http_server: Fix ws server handle length over 1440(MTU) messages incorrectly.
Closes https://github.com/espressif/esp-idf/issues/7202
2021-07-05 20:09:49 +08:00
Siarhei Volkau
ba15970abb esp_http_server, protocomm: Consider a connection as closed if recv() returns 0
This check prevents infinite loop on closed sockets

Closes https://github.com/espressif/esp-idf/pull/6541

Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
2021-06-08 05:48:30 +00:00
Jan Brudny
967e057906 esp-tls, esp_http_client and esp_http_server: update copyright notice 2021-05-31 20:06:09 +08:00
Aditya Patwardhan
3e82fcd566 esp_http_server: Fix transport_ctx not getting freed
Closes https://github.com/espressif/esp-idf/issues/6813
2021-04-07 05:25:39 +00:00
yuanjm
382fe8807d httpd: Support user_ctx in websocket handler callback request
Closes https://github.com/espressif/esp-idf/issues/6538
2021-03-10 12:31:38 +00:00
Mahavir Jain
907ea44ee9 Merge branch 'feature/http_server_optimizations' into 'master'
esp_http_server optimisations

Closes IDFGH-4484 and IDFGH-4741

See merge request espressif/esp-idf!12240
2021-03-08 09:01:20 +00:00
Shubham Kulkarni
6a7587d35f esp_http_server: Run format.sh script to fix code style issues 2021-03-04 04:08:47 +00:00
Jermolinski
282726b619 The httpd_sess_* functions have been re-designed to speed up the httpd server
Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>

Merges: https://github.com/espressif/esp-idf/pull/6313
2021-03-04 04:08:47 +00: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
yuanjm
da58235a0e components: Use CONFIG_LWIP_IPV6 to strip IPv6 function in components 2021-02-23 18:26:03 +08:00
David Cermak
c415c6f9a6 httpd: Fixed wrong header in ws_send_async() for lengthy packets
Closes https://github.com/espressif/esp-idf/issues/6196
2021-01-18 12:13:58 +00:00
Shubham Kulkarni
00876a8946 esp_http_server: Add lru_socket flag in sock_db to indicate httpd_sess_close is called from httpd_sess_close_lru 2021-01-15 05:53:41 +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
Angus Gratton
66fb5a29bb Whitespace: Automated whitespace fixes (large commit)
Apply the pre-commit hook whitespace fixes to all files in the repo.

(Line endings, blank lines at end of file, trailing whitespace)
2020-11-11 07:36:35 +00:00
Ivan Grokhotkov
b6467257b9 Merge branch 'feature/cmock_component' into 'master'
cmock as component replacing unity

See merge request espressif/esp-idf!9859
2020-09-10 16:06:20 +08: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
Jakob Hasse
20c068ef3b cmock: added cmock as component
* changing dependencies from unity->cmock
* added component.mk and Makefile.projbuild
* ignore test dir in gen_esp_err_to_name.py
* added some brief introduction of CMock in IDF
2020-09-02 16:38:37 +08: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
Shubham Kulkarni
0ec5096742 esp_http_server: Update LRU counter on accepting a new connection
Closes https://github.com/espressif/esp-idf/issues/3851
2020-06-26 05:29:00 +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
Piyush Shah
c2ab112590 esp_http_server: Fixed a bug which could cause issues with LRU purge
LRU counter should be started from 1, and not 0, so that all checks
work fine.

Closes https://github.com/espressif/esp-idf/issues/4753
2020-05-19 22:11:02 +05:30
Renz Bagaporo
3d0967a58a test: declare requirements and include dirs private 2020-03-23 10:58:50 +08: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
Konstantin Kondrashov
739eb05bb9 esp32: add implementation of esp_timer based on TG0 LAC timer
Closes: IDF-979
2020-02-06 14:00:18 +08:00
Chinmay Chhajed
a6cc964a26 esp_http_server : Bugfix in parsing of empty header values
This MR is intended to fix incorrect parsing of HTTP requests when empty header values are present.

The issue is was due to asymmetric behavior of `http_parser` library, which in case of:

    non-empty header values : invokes callbacks with the pointer to the start of a value
    empty header values : invokes callbacks with pointer to the start of next header or section

Since HTTP server relies on this pointer (along with length of the value) to locate the end of a value, and replace the line terminators (CRLFs) with null characters, the second case needed to be handled correctly.

Closes IDFGH-1539

Closes https://github.com/espressif/esp-idf/issues/3803
2019-09-06 11:02:36 +08:00
Roland Dobai
612db28b6f Fix error code collision and CI check 2019-08-29 08:14:08 +00:00
Piyush Shah
c93cab858e httpd_sess_close: Check for session validity before closing
If httpd_sess_trigger_close() gets called twice for the same socket,
the first httpd_sess_close() cb closes the correct socket, but the second
invocation closes the wrong socket which was just accepted and added to
the socket db. Checking for the lru counter will help identify this as the
counter is set only for requests actually served.
2019-08-06 19:31:57 +05:30
Anton Maklakov
afbaf74007 tools: Mass fixing of empty prototypes (for -Wstrict-prototypes) 2019-08-01 16:28:56 +07:00
xueyunfei
fa02598b5c lwip_2.1.2 for idf_4.0 2019-07-07 01:51:45 +00:00
Renz Christian Bagaporo
9b350f9ecc cmake: some formatting fixes
Do not include bootloader in flash target when secure boot is enabled.
Emit signing warning on all cases where signed apps are enabled (secure
boot and signed images)
Follow convention of capital letters for SECURE_BOOT_SIGNING_KEY
variable, since it is
relevant to other components, not just bootloader.
Pass signing key and verification key via config, not requiring
bootloader to know parent app dir.
Misc. variables name corrections
2019-06-21 19:53:29 +08:00
Renz Christian Bagaporo
9eccd7c082 components: use new component registration api 2019-06-21 19:53:29 +08: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
Angus Gratton
0458bacc4e Merge branch 'bugfix/httpd_log_purge' into 'master'
esp_http_server : Logging of purged data to monitor made configurable

Closes IDFGH-1034

See merge request idf/esp-idf!4941
2019-05-14 18:07:51 +08:00
Anurag Kar
6bf423d1e1 esp_http_server : Logging of purged data to monitor made configurable
List of changes:
* Kconfig option HTTPD_LOG_PURGE_DATA enables logging of purged data
* Kconfig option HTTPD_PURGE_BUF_LEN sets purge buffer length
* Purged data is logged in hex

Closes https://github.com/espressif/esp-idf/issues/3359
2019-05-10 14:25:39 +05:30
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
Anurag Kar
ffad8b27a3 esp_http_server : Allow binding to same address and port upon restarting server without delay
Issue : Restarting the server without 30sec delay between httpd_stop() and httpd_start() causes EADDRINUSE error
Resolution : Use setsockopt() to enable SO_REUSEADDR on listener socket

Closes https://github.com/espressif/esp-idf/issues/3381
2019-05-02 05:29:38 +00:00
Anurag Kar
9542063236 esp_http_server : Test added to check limit on max_open_sockets config option 2019-04-03 13:34:12 +00:00
Anurag Kar
7e676c1055 esp_http_server : Only accept new connections if server has capacity to handle more
This fix prevents HTTP server from accepting new connections when the total count of connected
sockets has reached the max_open_sockets limit set during configuration. The pending connections
are kept in backlog until atleast one of the connected sockets is closed. The maximum number of
connection requests that can kept in backlog is specified as backlog_conn configuration option.
Note that this modification has no effect when LRU purge is enabled.

Also added sanity check on setting for max_open_sockets during configuration.

Solution suggested by jimparis https://github.com/espressif/esp-idf/issues/3183#issue-421234265

Closes https://github.com/espressif/esp-idf/issues/3183
2019-04-03 13:34:12 +00:00
Anurag Kar
990af312d1 HTTP Server : Fix for tolerating LF terminated headers
List of changes:
* When parsing requests, count termination from LF characters only
* Correct memcpy() length parameter in httpd_unrecv() (pointed out by jimparis in GitHub issue thread)
* Use ssize_t to store results of length subtractions during parsing
* Modify some comments to reduce ambiguity

Closes https://github.com/espressif/esp-idf/issues/3182
2019-03-26 14:21:40 +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
Roland Dobai
37126d3451 Correct Kconfigs according to the coding style 2019-01-29 13:37:01 +01: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
21878d1bbf HTTP Server : Unit test added for httpd_uri_match_wildcard() function as given in https://github.com/espressif/esp-idf/pull/2581#issuecomment-430788473 2019-01-14 08:59:55 +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
Ondřej Hruška
91d6b3b989 Implement wildcard URI matching for http_server 2019-01-06 03:07:13 +05:30
Angus Gratton
61ee1bd31f Merge branch 'feature/esp_https_server' into 'master'
Add HTTPS Server component

See merge request idf/esp-idf!3608
2018-11-20 13:58:26 +08:00
Ivan Grokhotkov
6091021e83 unity: separate common and IDF specific functionality
New unity component can be used for testing other applications.
Upstream version of Unity is included as a submodule.
Utilities specific to ESP-IDF unit tests (partitions, leak checking
setup/teardown functions, etc) are kept only in unit-test-app.
Kconfig options are added to allow disabling certain Unity features.
2018-11-19 12:36:31 +08:00
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