Skip to content

Context.Path() confusing behaviour for 404 endpoints. #2384

@brietaylor

Description

@brietaylor

As documented: "Context.Path() returns the registered path for the handler."

I couldn't really find any documentation of what this is supposed to return if there's no registered handler (eg. a 404 in a middleware). Currently it just returns the request path, seems confusing to me, since the registered paths are trusted strings, whereas request paths can be anything.

This is causing an issue for us in the Prometheus middleware, which assumes Context.path to be a safe string from registered handlers, but it is not. labstack/echo-contrib#86

IMO it should be set to something like "" in this case, which would fix the issue in the middleware above, but also this is somewhat of a breaking change? Curious to hear others' thoughts on this.

Edit: Opened a PR: #2385

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions