Comments (7)
That seems like the right thing to do. Slating for 0.2.
from rocket.
As a side note, the docs also state that a 400 gets emitted if it fails to parse the form.
https://rocket.rs/guide/requests/#forms
This would need to be updated if #103 is merged
from rocket.
Actually, 400 (Bad Request) is the correct code to emit if the request cannot be parsed. 422 (Unprocessable Entity) on the other hand means, "The request data you gave is syntactically valid, but it doesn't fit the constraints for this route."
from rocket.
To clarify further because why not. 400
should be returned if the request body isn't JSON, XML, etc. Any other considerations (eg. an int vs a string or a parametric validation) should be 422
.
from rocket.
Alright! This is one of two remaining issues for 0.2!
So, looking at the RFC, section 8.2.1, we should return a 400
when any of the following occurs:
- A form string has no
=
at all or has no=
after an&
. - The form string contains spaces.
- The form string contains unencoded URL characters.
The first one is pretty easy to detect but requires a change to the FormItems
iterator. The second one means we have to check every string for spaces, which we can do efficiently if we change the FormItems
decorator again. The last one...seems expensive, and I don't really know what the point of it is besides being able to send it in the URL.
Would be good to know what other frameworks do here. My intuition is that we should just check for 1 and ignore 2 and 3. This can be done by simply adding a method to the FormItems
structure to see if there is any remaining, unparsed text. But even then: should Rocket just let this fly?
It's not clear to me what the correct approach is here.
[Copied this from #103]
from rocket.
I'm partial to just doing [1]. That's a simple parse failure.
I can't find the source, but I remember reading a quote (similar) to the following in a RFC (probably the HTML one).
Accept as much variation as feasible but return exactly 1 result.
I'd argue that while doing [2] and [3] are very cheap performance-wise (just a simple character rejection with a blacklist of only 7 characters) it feels like being overly strict. What happens if there exists a browser that decides it wants to send spaces? It's not ambiguous to accept spaces so I don't see a problem. I could see a warning log though.
from rocket.
What happens if there exists a browser that decides it wants to send spaces? It's not ambiguous to accept spaces so I don't see a problem. I could see a warning log though.
The short answer is that if the browser sends spaces, it is not in compliance with the RFC.
Consistent behavior globally is really valuable. Feature matrix hell is not fun.
Personally I caution against doing things that are technically possible without a substantial and valuable use case. The smaller the set of rules that describe the system, the easier it is for my limited human brain to reason about. Unnecessary complexity saps productivity like one would not believe.
from rocket.
Related Issues (20)
- Add SQLite extensions HOT 2
- Middleware that handles requests for static resources HOT 2
- Unable to build: no `Serialize` in `de` HOT 3
- Add default content_type for TempFile uploads HOT 2
- Could not find `json` in `serde` HOT 1
- Can't change IP that Rocket starts from. HOT 1
- Clippy lint: temporary with significant `Drop` can be early dropped HOT 1
- Rocket sometimes resets connection instead of responding with 413 error response HOT 2
- MiniJinja can't be used for templates HOT 1
- Routing by hostname HOT 10
- New release of rocket_dyn_templates HOT 3
- Redirector issue in TLS example HOT 5
- Deployment Docs - Static Files HOT 1
- FromForm Option<Result> with custom type HOT 4
- Possible error in the Json guard HOT 3
- Allow Generics in route functions HOT 1
- Caching a background image with the `Cache-Control` header HOT 2
- sslmode=required not working for rocket_db_pool with feature diesel_postgres HOT 1
- Fairing returns incorrect Content-Length for status 204 HOT 7
- No way to turn off coloured log output HOT 2
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 rocket.