Skip to content

Commit 89c83ae

Browse files
committed
Use serde_json::from_str instead of from_reader when deserialize Json
`serde_json::from_reader` is considerably slow for some reason. serde-rs/json#160
1 parent 5a9d857 commit 89c83ae

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

contrib/src/json.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ impl<T: DeserializeOwned> FromData for Json<T> {
9797
}
9898

9999
let size_limit = request.limits().get("json").unwrap_or(LIMIT);
100-
serde_json::from_reader(data.open().take(size_limit))
100+
let mut buf = String::new();
101+
data.open()
102+
.take(size_limit)
103+
.read_to_string(&mut buf)
104+
.map_err(|e| { error_!("IO Error: {:?}", e); e })
105+
.unwrap();
106+
serde_json::from_str(&buf)
101107
.map(|val| Json(val))
102108
.map_err(|e| { error_!("Couldn't parse JSON body: {:?}", e); e })
103109
.into_outcome(Status::BadRequest)

0 commit comments

Comments
 (0)