pub fn load_request_data<D: Deserialize>(req: &mut Request) -> Result<D> {
    if let Some(&ContentLength(length)) = req.headers.get() {
        if length > 1024 * 1024 * 10 {
            return Err(ApiError::PayloadTooLarge.into());
        }
    } else {
        return Err(ApiError::BadRequest.into());
    }

    let mut body: Vec<u8> = vec![];
    req.read_to_end(&mut body)?;

    Ok(match serde_json::from_slice(&body[..]) {
        Ok(data) => data,
        Err(err) => { return Err(ApiError::BadJson(Box::new(err)).into()); }
    })
}
/// Helper for the handlers to safely load request data.
Helper for the handlers to safely load request data.
Helper for the handlers to safely load request data .
pub fn load_request_data<D: Deserialize>(req: &mut Request) -> Result<D> {
    if let Some(&ContentLength(length)) = req.headers.get() {
        if length > 1024 * 1024 * 10 {
            return Err(ApiError::PayloadTooLarge.into());
        }
    } else {
        return Err(ApiError::BadRequest.into());
    }
    let mut body: Vec<u8> = vec![];
    req.read_to_end(&mut body)?;
    Ok(match serde_json::from_slice(&body[..]) {
        Ok(data) => data,
        Err(err) => { return Err(ApiError::BadJson(Box::new(err)).into()); }
    })
}
pub fn load_request_data < D : Deserialize > ( req : & mut Request ) -> Result < D > { if let Some ( & ContentLength ( length ) ) = req . headers . get ( ) { if length > 1024 * 1024 * 10 { return Err ( ApiError :: PayloadTooLarge . into ( ) ) ; } } else { return Err ( ApiError :: BadRequest . into ( ) ) ; } let mut body : Vec < u8 > = vec ! [ ] ; req . read_to_end ( & mut body ) ? ; Ok ( match serde_json :: from_slice ( & body [ .. ] ) { Ok ( data ) => data , Err ( err ) => { return Err ( ApiError :: BadJson ( Box :: new ( err ) ) . into ( ) ) ; } } ) }
Helper for the handlers to safely load request data.
Helper for the handlers to safely load request data .
req
&mut Request