dev: do something about HEAD requests
This commit is contained in:
@@ -11,3 +11,7 @@ This is a reimplementation of the oauth2 server I was making and forgot where I
|
||||
# License
|
||||
|
||||
All code licensed under the GPL-2.0-only.
|
||||
|
||||
# Known Issues
|
||||
|
||||
HTTP `HEAD` requests are not responded to properly, I'm exploring solutions but each one has its drawbacks to consider.
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
use actix_web::{
|
||||
HttpRequest, HttpResponse,
|
||||
web::{self, Bytes},
|
||||
};
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use futures_util::stream;
|
||||
|
||||
use crate::consts;
|
||||
@@ -26,6 +23,16 @@ fn mix_u32s(seed: impl Iterator<Item = u32>) -> u32 {
|
||||
}
|
||||
|
||||
pub async fn not_found(req: HttpRequest) -> HttpResponse {
|
||||
if req.method().as_str().eq_ignore_ascii_case("HEAD") {
|
||||
return HttpResponse::NotImplemented()
|
||||
.insert_header((
|
||||
"Unimplemented",
|
||||
"The HEAD method is not yet implemented \
|
||||
and this response is not valid for this endpoint",
|
||||
))
|
||||
.body(());
|
||||
}
|
||||
|
||||
let seed = req.path().as_bytes();
|
||||
let random = mix_u32s(seed.iter().copied().map(u32::from));
|
||||
|
||||
@@ -40,7 +47,7 @@ pub async fn not_found(req: HttpRequest) -> HttpResponse {
|
||||
Ok::<_, !>(web::Bytes::from(format!(
|
||||
"> {method} '{url}'\n404 NOT FOUND\nLet's all love lain\n\n"
|
||||
))),
|
||||
Ok(Bytes::from_static(res.as_bytes())),
|
||||
Ok(web::Bytes::from_static(res.as_bytes())),
|
||||
]))
|
||||
// .body(format!(
|
||||
// "> {method} '{url}'\n404 NOT FOUND\nLet's all love lain\n\n{res}"
|
||||
|
||||
Reference in New Issue
Block a user