-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPTIONS header has to be explicitly handled #67
Comments
I agree this isn't ideal. Before httpz supported middleware, when CORS was just a built-in part of the flow, it behaved like you'd expect. While I think about how to solve this, one temporary workaround it to define a catch-all route for options:
|
In terms of solving it, is OPTIONS as a method not a standard way for the client to request information about the route? if so, httpz could handle it implicitly. |
1 - Global middleware can now be defined. This allows middleware to execute even when no route is found. This can be useful for things like CORS which should likely answer an OPTIONS request even on a not found. 2 - When adding middleware to a route, you can now pick between an "append" or "replace" strategy. This controls how/if the middleware for a route are appended or replace the middleware for a group and then up the chain to the global. #67
When you create the router, you can now pass a list of middlewares. These will be globally applied (including to requests with no matching route): var router = server.router(.{.middlewares = .{cors}); Any route-specific middleware will be appended to the global list. Let me know if that solves the issue. |
I might be missing something, I don't know anything about the HTTP spec.
Using the built-in cors middleware, for each endpoint I have to explicitly declare both an
OPTIONS
handler as well as the handler for the endpoint:Otherwise,
OPTIONS /resources
returns404
and the browser freaks out.Am I expected to declare these
.options
endpoints myself, or should http.zig add them 'implicitly'?P.S. Great project, been very useful for me.
The text was updated successfully, but these errors were encountered: