Support missing Accept headers
This commit is contained in:
parent
3a909b9be2
commit
f56b49ddad
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-webfinger"
|
name = "actix-webfinger"
|
||||||
description = "Types and helpers to create and fetch Webfinger resources"
|
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"
|
license = "GPL-3.0"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
repository = "https://git.asonix.dog/Aardwolf/actix-webfinger"
|
repository = "https://git.asonix.dog/Aardwolf/actix-webfinger"
|
||||||
|
|
|
@ -32,7 +32,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.data(MyState {
|
.data(MyState {
|
||||||
domain: "asonix.dog".to_owned(),
|
domain: "localhost:8000".to_owned(),
|
||||||
})
|
})
|
||||||
.service(actix_webfinger::resource::<_, MyResolver>())
|
.service(actix_webfinger::resource::<_, MyResolver>())
|
||||||
})
|
})
|
||||||
|
|
19
src/lib.rs
19
src/lib.rs
|
@ -135,9 +135,9 @@ pub struct WebfingerGuard;
|
||||||
|
|
||||||
impl Guard for WebfingerGuard {
|
impl Guard for WebfingerGuard {
|
||||||
fn check(&self, request: &RequestHead) -> bool {
|
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() {
|
if let Ok(s) = val.to_str() {
|
||||||
return s.split(",").any(|v| {
|
s.split(",").any(|v| {
|
||||||
let v = if let Some(index) = v.find(';') {
|
let v = if let Some(index) = v.find(';') {
|
||||||
v.split_at(index).0
|
v.split_at(index).0
|
||||||
} else {
|
} else {
|
||||||
|
@ -145,16 +145,23 @@ impl Guard for WebfingerGuard {
|
||||||
};
|
};
|
||||||
let trimmed = v.trim();
|
let trimmed = v.trim();
|
||||||
|
|
||||||
|
// The following accept mimes are valid
|
||||||
trimmed == "application/jrd+json"
|
trimmed == "application/jrd+json"
|
||||||
|| trimmed == "application/json"
|
|| trimmed == "application/json"
|
||||||
|| trimmed == "application/*"
|
|| trimmed == "application/*"
|
||||||
|| trimmed == "*/*"
|
|| trimmed == "*/*"
|
||||||
}) && request.method == Method::GET;
|
})
|
||||||
}
|
} else {
|
||||||
}
|
// unparsable accept headers are not valid
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// no accept header is valid i guess
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
valid_accept && request.method == Method::GET
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A simple way to mount the webfinger service to your Actix Web application
|
/// A simple way to mount the webfinger service to your Actix Web application
|
||||||
|
|
Loading…
Reference in a new issue