Skip to content

Bug: HTTP server dynamic handler not triggered due to static resource overlap #101429

@azais-corentin

Description

@azais-corentin

Describe the bug

I have an issue using Zephyr RTOS's HTTP server:

static struct http_resource_detail_static_fs frontendFsDetail = {
    .common =
        {
            .bitmask_of_supported_http_methods = BIT(HTTP_GET),
            .type = HTTP_RESOURCE_TYPE_STATIC_FS,
        },
    .fs_path = "/lfs",
};

static struct http_resource_detail_dynamic statusJsonDetail = {
    .common =
        {
            .bitmask_of_supported_http_methods = BIT(HTTP_GET),
            .type = HTTP_RESOURCE_TYPE_DYNAMIC,
            .content_type = "application/json",
        },
    .cb = httpHandlerStatusJson,
    .user_data = nullptr,
};

HTTP_RESOURCE_DEFINE(frontendStatusResource, httpService, "/status", &frontendFsDetail);
HTTP_RESOURCE_DEFINE(statusJsonResource, httpService, "/status/json", &statusJsonDetail);

I have a static filesystem resource at "/status" and a dynamic JSON resource at "/status/json".
However, when I try to access "/status/json", I receive an error net_http_server: fs_stat /lfs/status/json: -2 (expected) but my httpHandlerStatusJson handler is never invoked.

I believe this is a bug since I'm not using a wildcard resource and the static resource should not match "/status/json".

I have verified that the handler is not called using LOGs. I have also verified that my handler works properly by changing /status/json to /status2/json.

Zephyr v4.3.0

Regression

  • This is a regression.

Steps to reproduce

  1. Set up the HTTP server with the above resource definitions.
  2. Attempt to access "/status/json" via a web client or curl.
  3. Observe the net_http_server: fs_stat /lfs/status/json: -2 error and that the handler is not triggered.

Relevant log output

net_http_server: fs_stat /lfs/status/json: -2

Impact

Not sure

Environment

No response

Additional Context

No response

Metadata

Metadata

Assignees

Labels

area: HTTPHTTP client/server supportbugThe issue is a bug, or the PR is fixing a bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions