diff options
author | xengineering <me@xengineering.eu> | 2025-03-21 22:26:19 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2025-03-21 22:26:19 +0100 |
commit | 61e108a0ae856b3e1c849482d0008f698d41db27 (patch) | |
tree | b508f088915653386c0a0ccfce3aa04707f0e1b4 | |
parent | 0ec1b2088df75e0bed587acdd25e00a69edf3556 (diff) | |
download | iot-contact-61e108a0ae856b3e1c849482d0008f698d41db27.tar iot-contact-61e108a0ae856b3e1c849482d0008f698d41db27.tar.zst iot-contact-61e108a0ae856b3e1c849482d0008f698d41db27.zip |
fw: http: Add /favicon.ico handler
Common browsers always request this URL. Not responding to it shows up
as an error.
To silence this error report the firmware just responds with HTTP 204 No
Content since a favicon is currently not available.
-rw-r--r-- | fw/src/http.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/fw/src/http.c b/fw/src/http.c index 36ad7c0..96a70fe 100644 --- a/fw/src/http.c +++ b/fw/src/http.c @@ -11,6 +11,7 @@ #include <zephyr/logging/log.h> #include <zephyr/net/http/server.h> #include <zephyr/net/http/service.h> +#include <zephyr/net/http/status.h> LOG_MODULE_REGISTER(http); @@ -31,11 +32,39 @@ struct http_resource_detail_static index_resource_detail = { .static_data_len = sizeof(index_html_gz), }; +static int favicon_handler( + struct http_client_ctx *client, + enum http_data_status status, + const struct http_request_ctx *request_ctx, + struct http_response_ctx *response_ctx, + void *user_data +) { + LOG_DBG("Handling favicon request"); + + response_ctx->body = NULL; + response_ctx->body_len = 0; + response_ctx->final_chunk = true; + response_ctx->status = HTTP_204_NO_CONTENT; + + LOG_DBG("Favicon request handled"); + return 0; +} + +static struct http_resource_detail_dynamic favicon_resource_detail = { + .common = { + .type = HTTP_RESOURCE_TYPE_DYNAMIC, + .bitmask_of_supported_http_methods = BIT(HTTP_GET), + }, + .cb = favicon_handler, + .user_data = NULL, +}; + static uint16_t http_port = 80; HTTP_SERVICE_DEFINE(http_service, NULL, &http_port, 1, 10, NULL, NULL); HTTP_RESOURCE_DEFINE(index_resource, http_service, "/", &index_resource_detail); +HTTP_RESOURCE_DEFINE(favicon_resource, http_service, "/favicon.ico", &favicon_resource_detail); int init_http_server(void) { LOG_DBG("Starting HTTP server"); |