Skip to content

Commit c66c615

Browse files
committed
[bitreq] Check utf-8 while deserializing JSON body
While deserializing, `serde_json::from_slice` validates utf-8 as needed. So instead of making two passes on the response body, one to validate utf-8, and another to deserialize the object, we can let `serde_json::from_slice` check utf-8 as needed during deserialization. `Response::json` now returns `Error::SerdeJsonError` instead of `Error::InvalidUtf8InBody` if invalid utf-8 bytes are found during deserialization.
1 parent d31fc06 commit c66c615

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

bitreq/src/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl Response {
248248
where
249249
T: serde::de::Deserialize<'a>,
250250
{
251-
match serde_json::from_str(self.as_str()?) {
251+
match serde_json::from_slice(self.as_bytes()) {
252252
Ok(json) => Ok(json),
253253
Err(err) => Err(Error::SerdeJsonError(err)),
254254
}

0 commit comments

Comments
 (0)