Closed ArcaneEcholan closed 1 month ago
I wonder that, is the Middleware component a new concept in drogon? If not, why can I find any clue about it in the latest version of release?
Yes, it was added only recently. Thought HttpMiddleware is the base class of HttpFilter, it is actually designed based on HttpFilter, which exists for long.
I want people to know and use this feature earlier, so I added the document soon.
I wonder that, is the Middleware component a new concept in drogon? If not, why can I find any clue about it in the latest version of release?
Yes, it was added only recently. Thought HttpMiddleware is the base class of HttpFilter, it is actually designed based on HttpFilter, which exists for long.
I want people to know and use this feature earlier, so I added the document soon.
Ok, I hope this feature could be shipped to release asap, this issue shall be closed.
Requirement
I want to add cors headers to the response so the browser won't block my cross-origin request.
Though I can write a function called
add_cors_headers(callback)
, and invoke it in every method in my controllers, I don't think it's a good workaround.The
HttpFilter
class does not help, since it does not provide a post processing function.My Solution
I learned that drogon has "Middleware" components from the docs: https://github.com/drogonframework/drogon-docs/blob/master/ENG-05-Middleware-and-Filter.md#middleware-definition.
The middleware example showed in the docs above is able to do the post processing like this:
which indeed meet my requirement.
Problem
But I found out that in the latest tag, like v1.9.4, the
drogon/HttpMiddleware.h
class could not be found in the codebase.I finally found
drogon/HttpMiddleware.h
on the master branch.I wonder that, is the
Middleware
component a new concept in drogon? If not, why can I find any clue about it in the latest version of release?Expectation
In my coding experiences, the post processing is a very common component for a web server framework, and it's not strange to find requirements about do something common things after each request.
So If you could, I recommend to include the Middleware feature in the upcoming releases, or at least it should be supported asap.