Skip to content

Middleware is applied last to first #786

Closed

Description

@wttw

I'm using a strict chi server.

ChiServerOptions takes a slice of middleware, []MiddleWareFunc. When these are applied they're chained in the order of the slice, meaning that the middleware executes last to first.

I'd expect them to be executed first to last, as most other Go middleware chains do (by iterating through the slice in reverse order).

Activity

  1. jazware commented on Oct 14, 2022

    @jazware
    Contributor

    Looks like chi's backwards chaining logic is written in their chain function here. Should be trivial to update in the chi-middleware template. I'll throw a quick patch together.

  2. jazware commented on Oct 22, 2022

    @jazware
    Contributor

    This should now be supported in the next release (including this PR) using the following options in your config YAML:

    compatibility:
      apply-chi-middleware-first-to-last: true

    This issue can be closed (but I don't have permissions to close it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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