Prevent panic on InboxRequestGuard
This commit is contained in:
parent
f6c13cf313
commit
1943bcd7f5
1 changed files with 10 additions and 10 deletions
|
@ -1,8 +1,11 @@
|
||||||
use crate::http::{
|
use crate::http::{
|
||||||
comment::get_apub_comment,
|
comment::get_apub_comment,
|
||||||
community::{
|
community::{
|
||||||
community_inbox, get_apub_community_followers, get_apub_community_http,
|
community_inbox,
|
||||||
get_apub_community_moderators, get_apub_community_outbox,
|
get_apub_community_followers,
|
||||||
|
get_apub_community_http,
|
||||||
|
get_apub_community_moderators,
|
||||||
|
get_apub_community_outbox,
|
||||||
},
|
},
|
||||||
get_activity,
|
get_activity,
|
||||||
person::{get_apub_person_http, get_apub_person_outbox, person_inbox},
|
person::{get_apub_person_http, get_apub_person_outbox, person_inbox},
|
||||||
|
@ -11,7 +14,7 @@ use crate::http::{
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
guard::{Guard, GuardContext},
|
guard::{Guard, GuardContext},
|
||||||
http::Method,
|
http::{header, Method},
|
||||||
web,
|
web,
|
||||||
};
|
};
|
||||||
use http_signature_normalization_actix::digest::middleware::VerifyDigest;
|
use http_signature_normalization_actix::digest::middleware::VerifyDigest;
|
||||||
|
@ -65,15 +68,12 @@ pub fn config(cfg: &mut web::ServiceConfig, settings: &Settings) {
|
||||||
struct InboxRequestGuard;
|
struct InboxRequestGuard;
|
||||||
|
|
||||||
impl Guard for InboxRequestGuard {
|
impl Guard for InboxRequestGuard {
|
||||||
fn check(&self, request: &GuardContext) -> bool {
|
fn check(&self, ctx: &GuardContext) -> bool {
|
||||||
if request.head().method != Method::POST {
|
if ctx.head().method != Method::POST {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if let Some(val) = request.head().headers.get("Content-Type") {
|
if let Some(val) = ctx.head().headers.get(header::CONTENT_TYPE) {
|
||||||
return val
|
return val.as_bytes().starts_with(b"application/");
|
||||||
.to_str()
|
|
||||||
.expect("Content-Type header contains non-ascii chars.")
|
|
||||||
.starts_with("application/");
|
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue