Support missing Accept headers

This commit is contained in:
asonix 2020-03-17 11:24:51 -05:00
parent 3a909b9be2
commit f56b49ddad
3 changed files with 14 additions and 7 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "actix-webfinger"
description = "Types and helpers to create and fetch Webfinger resources"
version = "0.3.0-alpha.2"
version = "0.3.0-alpha.3"
license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/Aardwolf/actix-webfinger"

View file

@ -32,7 +32,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
HttpServer::new(|| {
App::new()
.data(MyState {
domain: "asonix.dog".to_owned(),
domain: "localhost:8000".to_owned(),
})
.service(actix_webfinger::resource::<_, MyResolver>())
})

View file

@ -135,9 +135,9 @@ pub struct WebfingerGuard;
impl Guard for WebfingerGuard {
fn check(&self, request: &RequestHead) -> bool {
if let Some(val) = request.headers().get("Accept") {
let valid_accept = if let Some(val) = request.headers().get("Accept") {
if let Ok(s) = val.to_str() {
return s.split(",").any(|v| {
s.split(",").any(|v| {
let v = if let Some(index) = v.find(';') {
v.split_at(index).0
} else {
@ -145,15 +145,22 @@ impl Guard for WebfingerGuard {
};
let trimmed = v.trim();
// The following accept mimes are valid
trimmed == "application/jrd+json"
|| trimmed == "application/json"
|| trimmed == "application/*"
|| trimmed == "*/*"
}) && request.method == Method::GET;
})
} else {
// unparsable accept headers are not valid
false
}
}
} else {
// no accept header is valid i guess
true
};
false
valid_accept && request.method == Method::GET
}
}