prepare for peehaitchpee

This commit is contained in:
2025-05-02 17:18:34 +02:00
parent abe2171e19
commit 93a69fd89b
2 changed files with 16 additions and 6 deletions

View File

@@ -9,4 +9,4 @@ memory_limit = 50
interval = 10
[push]
endpoint = "http://[::1]:8081/push"
endpoint = "http://[::1]:8081/api.php?cmd=newmodmessages"

View File

@@ -202,6 +202,7 @@ struct PushEndpoint<'a> {
port: u16,
addr: String,
authority: String,
path_and_query: String,
}
impl<'a> PushEndpoint<'a> {
@@ -210,7 +211,12 @@ impl<'a> PushEndpoint<'a> {
let port = uri.port_u16().ok_or("no port provided")?;
let addr = format!("{}:{}", host, port);
let authority = uri.authority().ok_or("no authority provided")?.to_string();
Ok(Self { uri, host, port, addr, authority })
let mut path_and_query: String = uri.path().to_string();
match uri.query() {
Some(v) => path_and_query.push_str(&format!("?{}", v)),
None => {},
}
Ok(Self { uri, host, port, addr, authority, path_and_query })
}
}
@@ -248,7 +254,8 @@ fn make_push_request<'a>(
) -> Result<hyper::Request<Full<Bytes>>, ()> {
let Ok(body) = serde_json::to_string(questions) else { return Err(()); };
hyper::Request::builder()
.uri(uri.uri)
.uri(&uri.path_and_query)
.method(hyper::Method::POST)
.header(hyper::header::HOST, &uri.authority)
.header(hyper::header::CONTENT_TYPE, "application/json")
.body(Full::new(Bytes::from(body))).map_err(|_| ())
@@ -280,9 +287,12 @@ async fn push_questions<'a>(questions: &HashSet<String>, uri: &PushEndpoint<'a>)
log!(err "could not construct push questions request");
return Err(());
};
let Ok(res) = conn.send_request(req).await else {
log!(err "could not send questions request to push endpoint");
return Err(());
let res = match conn.send_request(req).await {
Ok(v) => v,
Err(e) => {
log!(err "could not send questions request to push endpoint: {:?}", e);
return Err(());
},
};
if res.status() != hyper::StatusCode::OK {
log!(err "got non-200 response from push endpoint");