Comments (4)
Another similar problem involving the same design choice of routing aforementioned:
From the perspective of the semantics of HTTP methods, 405 Method Not Allowed
is a better choice over 404 Not Found
when there is an endpoint on a specific route path but request methods are not matched.
For example, https://github.com/rustasync/tide/blob/279e0f05a0a24fba9fc192f1d7956ad60fa0cf24/examples/messages.rs#L69
registers POST
method on /message
. It is supposed to response with 405 Method Not Allowed
HTTP status which clearly indicates that the request method is unexpected but the resource (path) is valid.
This behaviour is adhered by most matured Web framework in other programming languages. But it seems that many of the famous Web frameworks in Rust prefer to take the contrary way. There would be some performance penalty to be compliant, but I think it is worth discussing.
Update: The 404/405 problem has been fixed in https://github.com/http-rs/tide/pull/388/files.
from tide.
Just a remark on this (and also to the related PR at #104), it seems that Tide currently stores routes as a HashMap keyed on HTTP method, with values being the routers that contain endpoints with the given HTTP method (and accessed through the URL path).
This is just my idea, but one naive way of adding automatic support for OPTIONS
is probably to just key on every available HTTP endpoint (GET
/POST
/PUT
/DELETE
/etc.) and see if the route exists at that particular resource. It seems a little inefficient, since in the end we're making a total of at least 7 calls (HEAD
exists if GET
does, and OPTIONS
always exists) as per all of them, but maybe there's a more efficient way of doing this?
That or we somehow keep some other data store inline with the router that keys in the opposite direction, i.e. paths (sans extracted path strings like :id
or :name
) -> available methods.
from tide.
Any progress on this? It's on the 0.1 milestone, but we're already at 0.6... I'm willing to help out if you point me in the right direction.
from tide.
Note from triage: We handle CORS through the CorsMiddleware
; OPTIONS
is handled inside the Tide router. We should add docs for this though.
We're unsure however if simplify specifying the middleware also setups the options endpoint; it's been a while. We should make it so that we can enable that. One way to get there is by enabling middleware to run before the router, which is something we may want to do for other reasons as well.
from tide.
Related Issues (20)
- `req.body_json().await?` Get `serde_json::error::Error` HOT 2
- SessionMiddleware and RedisSessionStore HOT 3
- Unexpected Behaviour in 0.17.0-beta.1 HOT 5
- Cookie_string parsed incorrectly when reading an incoming cookie. HOT 4
- dinamycally check allowed origins (or with a regex) HOT 1
- WASM support HOT 2
- How to do RBAC authorization when using tide? HOT 1
- Error messages are not returned HOT 5
- Stop a Tide server (not graceful shutdown) HOT 1
- Support uploads (100 Continue) HOT 4
- Route introspection? HOT 2
- I don't see the code that implements &str for the listen method
- Does tide plan to support http2? HOT 5
- Proposal: Refactor Middleware Execution / Next with Cursors and Async Recursion HOT 1
- Chat link is invalid HOT 1
- serve_dir doesn't seem to work and even panics in some cases HOT 2
- failed to select version 0.17.0 (copied the one given in the doc) and did a cargo run
- Nested endpoints have less priority than wildcards
- Potential security issue HOT 1
- Embed Assets to Binary
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tide.