Dissociate content-type and token check
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
d73e149cb4
commit
0bf9f107b5
1 changed files with 7 additions and 11 deletions
14
src/web.rs
14
src/web.rs
|
@ -42,23 +42,19 @@ async fn webhooks_inner(req: Request<Incoming>, 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);
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue