fix: return a 405 for GET and DELETE if stateful_mode=false (#331)
This commit is contained in:
parent
179296134a
commit
d251800d19
1 changed files with 10 additions and 5 deletions
|
|
@ -111,15 +111,20 @@ where
|
||||||
B::Error: Display,
|
B::Error: Display,
|
||||||
{
|
{
|
||||||
let method = request.method().clone();
|
let method = request.method().clone();
|
||||||
let result = match method {
|
let allowed_methods = match self.config.stateful_mode {
|
||||||
Method::GET => self.handle_get(request).await,
|
true => "GET, POST, DELETE",
|
||||||
Method::POST => self.handle_post(request).await,
|
false => "POST",
|
||||||
Method::DELETE => self.handle_delete(request).await,
|
};
|
||||||
|
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
|
// Handle other methods or return an error
|
||||||
let response = Response::builder()
|
let response = Response::builder()
|
||||||
.status(http::StatusCode::METHOD_NOT_ALLOWED)
|
.status(http::StatusCode::METHOD_NOT_ALLOWED)
|
||||||
.header(ALLOW, "GET, POST, DELETE")
|
.header(ALLOW, allowed_methods)
|
||||||
.body(Full::new(Bytes::from("Method Not Allowed")).boxed())
|
.body(Full::new(Bytes::from("Method Not Allowed")).boxed())
|
||||||
.expect("valid response");
|
.expect("valid response");
|
||||||
return response;
|
return response;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue