rustfmt: hard_tabs = true

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-05-20 19:34:08 +02:00
commit 36673bd5bf
4 changed files with 56 additions and 55 deletions

View file

@ -23,26 +23,26 @@ use hyper::{body, header, Body, Method, Request, Response};
use log::{debug, error};
fn error_res<E: std::fmt::Debug>(e: E) -> Result<Response<Body>, Infallible> {
error!("error response: {:?}", e);
error!("error response: {:?}", e);
let text = format!("{:?}", e);
let res = Response::builder()
.status(400)
.body(Body::from(Vec::from(text.as_bytes())))
.unwrap();
Ok(res)
let text = format!("{:?}", e);
let res = Response::builder()
.status(400)
.body(Body::from(Vec::from(text.as_bytes())))
.unwrap();
Ok(res)
}
async fn webhooks_inner(req: Request<Body>) -> Result<Response<Body>, Error> {
match req.method() {
&Method::POST => (),
_ => return Err(Error::MethodMismatch),
}
match req.method() {
&Method::POST => (),
_ => return Err(Error::MethodMismatch),
}
debug!("Headers: {:?}", req.headers());
debug!("Headers: {:?}", req.headers());
let headers = req.headers();
if let Some(content_type) = headers.get(header::CONTENT_TYPE) &&
let headers = req.headers();
if let Some(content_type) = headers.get(header::CONTENT_TYPE) &&
let Some(token) = headers.get("X-Gitlab-Token") {
if content_type != "application/json" {
return Err(Error::InvalidContentType);
@ -53,14 +53,14 @@ async fn webhooks_inner(req: Request<Body>) -> Result<Response<Body>, Error> {
}
}
let tmp = body::to_bytes(req.into_body()).await?;
let text: &str = from_utf8(&tmp)?;
let json: WebHook = serde_json::from_str(text)?;
debug!("Passed: {:?}", json);
let tmp = body::to_bytes(req.into_body()).await?;
let text: &str = from_utf8(&tmp)?;
let json: WebHook = serde_json::from_str(text)?;
debug!("Passed: {:?}", json);
Ok(Response::new("Hello world".into()))
Ok(Response::new("Hello world".into()))
}
pub async fn webhooks(req: Request<Body>) -> Result<Response<Body>, Infallible> {
webhooks_inner(req).await.or_else(error_res)
webhooks_inner(req).await.or_else(error_res)
}