Skip to content

Commit a6faa14

Browse files
Check event type before handling
1 parent a967045 commit a6faa14

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

site/src/server.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,9 +1077,26 @@ async fn serve_req(ctx: Arc<Server>, req: Request) -> Result<Response, ServerErr
10771077
.body(hyper::Body::empty())
10781078
.unwrap());
10791079
}
1080-
Ok(to_response(
1081-
handle_github(body!(parse_body(&body)), data.clone()).await,
1082-
))
1080+
let event = req.headers.get("X-GitHub-Event").cloned();
1081+
let event = event.and_then(|g| g.to_str().ok().map(|s| s.to_owned()));
1082+
let event = match event {
1083+
Some(v) => v,
1084+
None => {
1085+
return Ok(http::Response::builder()
1086+
.status(StatusCode::OK)
1087+
.body(hyper::Body::from("missing event header"))
1088+
.unwrap())
1089+
}
1090+
};
1091+
match event.as_str() {
1092+
"issue_comment" => Ok(to_response(
1093+
handle_github(body!(parse_body(&body)), data.clone()).await,
1094+
)),
1095+
_ => Ok(http::Response::builder()
1096+
.status(StatusCode::OK)
1097+
.body(hyper::Body::from(format!("unknown event: {}", event)))
1098+
.unwrap()),
1099+
}
10831100
} else if p == "/perf/self-profile" {
10841101
Ok(to_response(
10851102
handle_self_profile(body!(parse_body(&body)), &data).await,

0 commit comments

Comments
 (0)