fix: return a 405 for GET and DELETE if stateful_mode=false (#331)

This commit is contained in:
Nate Usher 2025-07-28 11:41:17 -07:00 committed by GitHub
parent 179296134a
commit d251800d19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -111,15 +111,20 @@ where
B::Error: Display,
{
let method = request.method().clone();
let result = match method {
Method::GET => self.handle_get(request).await,
Method::POST => self.handle_post(request).await,
Method::DELETE => self.handle_delete(request).await,
let allowed_methods = match self.config.stateful_mode {
true => "GET, POST, DELETE",
false => "POST",
};
let result = match (method, self.config.stateful_mode) {
(Method::POST, _) => self.handle_post(request).await,
// if we're not in stateful mode, we don't support GET or DELETE because there is no session
(Method::GET, true) => self.handle_get(request).await,
(Method::DELETE, true) => self.handle_delete(request).await,
_ => {
// Handle other methods or return an error
let response = Response::builder()
.status(http::StatusCode::METHOD_NOT_ALLOWED)
.header(ALLOW, "GET, POST, DELETE")
.header(ALLOW, allowed_methods)
.body(Full::new(Bytes::from("Method Not Allowed")).boxed())
.expect("valid response");
return response;