-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Return a 413 instead of 400 when data limit is exceeded #972
Copy link
Copy link
Closed
Labels
enhancementA minor feature requestA minor feature requestrequestRequest for new functionalityRequest for new functionality
Milestone
Description
Hey there,
when sending a too large JSON payload (i.e. larger than the specified limit) Rocket will show a missleading error message in the debug log and respond with 400 Bad Request.
Instead of this behaviour, I'd expect Rocket to show a error message mentioning the too large payload and respond with 413 Payload Too Large.
Rocket version: 0.4.0
OS: Debian buster (10.0)
Code:
#![feature(proc_macro_hygiene, decl_macro)]
use rocket::*;
use rocket_contrib::json::Json;
#[post("/", data = "<data>")]
fn x(data: Json<String>) {}
fn main() {
ignite().mount("/", routes![x]).launch();
}
$ curl -H Content-Type:\ application/json -d @really-large-json-file http://localhost:8000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>400 Bad Request</title>
</head>
<body align="center">
<div align="center">
<h1>400: Bad Request</h1>
<p>The request could not be understood by the server due
to malformed syntax.</p>
<hr />
<small>Rocket</small>
</div>
</body>
</html>
🔧 Configured for development.
=> address: localhost
=> port: 8000
=> log: normal
=> workers: 8
=> secret key: generated
=> limits: forms = 32KiB
=> keep-alive: 5s
=> tls: disabled
🛰 Mounting /:
=> POST / (x)
🚀 Rocket has launched from http://localhost:8000
POST / application/json:
=> Matched: POST / (x)
=> Warning: Data left unread. Force closing network stream.
=> Error: Couldn't parse JSON body: Error("EOF while parsing a string", line: 1, column: 1048576)
=> Outcome: Failure
=> Warning: Responding with 400 Bad Request catcher.
=> Response succeeded.
Best,
Felix
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementA minor feature requestA minor feature requestrequestRequest for new functionalityRequest for new functionality