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 more `block helpers` to the `hbs` template example
- FromForm derive macro uses removed private_in_public lint HOT 2
- The path to Rocket.toml is not relative![] HOT 4
- Tests failing on master HOT 2
- impl<R: Responder> Responder for MutexGuard<R> HOT 1
- Bugs in negated `in` expressions HOT 1
- TempFile should be able to be read like a Stream HOT 1
- Error with validate macro in a form HOT 3
- Don't 404 on invalid input HOT 11
- attach(rocket_dyn_templates::Template::fairing()) panics with open square bracket in project path HOT 1
- Can the framework handle multiple files?
- `uri!` macro does not accept routes defined as constants HOT 5
- Cors docs and examples HOT 1
- Path to `contrib` repositories is not correct in sub `Cargo.toml` files HOT 1
- Force enable color output HOT 2
- Getting several lints on a #[derive(FromForm)] HOT 1
- Receiving ">>> Request guard `…` is forwarding" messages with log_level=critical HOT 6
- debug!("Received request: {:#?}", hyp_req); HOT 4
- Can't make private cookie not secure HOT 4
- Rocket does not return a 413 when the data submitted in a form exceeds the limit HOT 7
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.