Skip to content

Shouldn't Middleware functions take &mut self? #48

Closed
@bIgBV

Description

@bIgBV

Is there any reason why middleware functions cannot take &mut self? Middleware could enable storing some state when a request comes in and then use that state during the response phase. I'm facing the same issue right now when implementing #8. I figured that at the minimum when someone firsts starts using Tide, they should see a simple log in the terminal of the format:

<timestamp> <http method> <path> <statuscode>

But in order to do so, I need to store method and path information which is only present on the Request object and access them when the response function is called by the call method in Server.

I imagine that there are many such usecases where middleware would be storing information when the request method is called. An example that comes to mind is a caching middleware.

Therefore, I think that the request and response methods of the Middleware trait should take &mut self. Or is there a better way to go about solving this?

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