mirror of
https://github.com/neondatabase/neon.git
synced 2026-06-02 04:50:38 +00:00
support seeded deser
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
future::Future,
|
||||
marker::PhantomData,
|
||||
sync::Arc,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
@@ -148,6 +149,7 @@ impl JwkCacheEntryLock {
|
||||
Ok(r) => {
|
||||
let resp: http::Response<reqwest::Body> = r.into();
|
||||
match parse_json_body_with_limit::<jose_jwk::JwkSet, _>(
|
||||
PhantomData,
|
||||
resp.into_body(),
|
||||
MAX_JWK_BODY_SIZE,
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::time::Duration;
|
||||
use bytes::Bytes;
|
||||
use http_body_util::BodyExt;
|
||||
use hyper1::body::Body;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::de::DeserializeSeed;
|
||||
|
||||
pub(crate) use reqwest::{Request, Response};
|
||||
pub(crate) use reqwest_middleware::{ClientWithMiddleware, Error};
|
||||
@@ -122,7 +122,8 @@ pub(crate) enum ReadPayloadError<E> {
|
||||
LengthExceeded(usize),
|
||||
}
|
||||
|
||||
pub(crate) async fn parse_json_body_with_limit<D: DeserializeOwned, E>(
|
||||
pub(crate) async fn parse_json_body_with_limit<D, E>(
|
||||
seed: impl for<'de> DeserializeSeed<'de, Value = D>,
|
||||
mut b: impl Body<Data = Bytes, Error = E> + Unpin,
|
||||
limit: usize,
|
||||
) -> Result<D, ReadPayloadError<E>> {
|
||||
@@ -151,7 +152,7 @@ pub(crate) async fn parse_json_body_with_limit<D: DeserializeOwned, E>(
|
||||
}
|
||||
}
|
||||
|
||||
Ok(serde_json::from_slice::<D>(&bytes)?)
|
||||
Ok(seed.deserialize(&mut serde_json::Deserializer::from_slice(&bytes))?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::pin;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -605,6 +606,7 @@ async fn handle_db_inner(
|
||||
|
||||
let fetch_and_process_request = Box::pin(async {
|
||||
let payload = parse_json_body_with_limit(
|
||||
PhantomData,
|
||||
request.into_body(),
|
||||
config.http_config.max_request_size_bytes as usize,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user