Replies: 2 comments 15 replies
-
That issue is slightly out of date. |
Beta Was this translation helpful? Give feedback.
3 replies
-
pub async fn parse_fields(
State(app): State<Arc<App>>,
_session: WritableSession,
request: Request<hyper::Body>,
next: Next<hyper::Body>,
) -> Result<impl IntoResponse, Response> {
let (mut parts, body) = request.into_parts();
let bytes = hyper::body::to_bytes(body)
.await
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response())?;
let header = parts.headers.get(CONTENT_TYPE).unwrap();
let boundary = multer::parse_boundary(header.to_str().unwrap()).unwrap();
let multipart = multer::Multipart::with_reader(&*bytes, boundary);
let input = app.models.parse_fields(multipart).await.unwrap();
let captcha = parts
.headers
.get_all(COOKIE)
.iter()
.filter_map(|header| header.to_str().ok())
.flat_map(|header| header.split(';'))
.filter_map(|header| Cookie::parse_encoded(header.trim()).ok())
.find(|cookie| cookie.name() == "captcha");
let expected_hash = hash(input.captcha.as_bytes()).await;
info!(
"received captcha: {}, captcha hash: {}",
&input.captcha,
base64::encode(expected_hash.clone())
);
match captcha {
Some(captcha) if captcha.value() == base64::encode(expected_hash) => {
parts.extensions.insert(Ok::<Input, RequestError>(input));
let request = Request::from_parts(parts, hyper::Body::from(bytes.clone()));
Ok(next.run(request).await)
}
_ => {
parts
.extensions
.insert(Err::<Input, RequestError>(RequestError::IncorrectCaptcha));
let request = Request::from_parts(parts, hyper::Body::from(bytes.clone()));
Ok(next.run(request).await)
}
}
} I don't see what's wrong since the last statement, my match pattern returns a |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
According to #1110 the way to use
RequestBodyLimitLayer
is to return aRouter<http_body::Limited<Body>>
but this doesn't seem to work in my case. I have several layers on top of my routes so it's pretty tricky to find what part of my code is to blame.Code:
Compiler error:
Let me know if more details are required to fix my issue.
Beta Was this translation helpful? Give feedback.
All reactions