diff --git a/src/web.rs b/src/web.rs index 1714a78..0892754 100644 --- a/src/web.rs +++ b/src/web.rs @@ -42,23 +42,19 @@ async fn webhooks_inner(req: Request, token: Option<&String>) -> Resul _ => return Err(Error::MethodMismatch), } - if token.is_none() { - return Err(Error::InvalidToken); - } - let token: &str = token.unwrap(); - debug!("Headers: {:?}", req.headers()); let headers = req.headers(); if let Some(content_type) = headers.get(header::CONTENT_TYPE) - && let Some(header_token) = headers.get("X-Gitlab-Token") + && content_type != "application/json" { - if content_type != "application/json" { - return Err(Error::InvalidContentType); - } + return Err(Error::InvalidContentType); + } - if header_token != token { - return Err(Error::InvalidToken); + if let Some(token) = token { + match headers.get("X-Gitlab-Token") { + Some(val) if val == token => (), + _ => return Err(Error::InvalidToken), } }