diff --git a/config/dev.toml b/config/dev.toml index 8d53fb2..bec9e5b 100644 --- a/config/dev.toml +++ b/config/dev.toml @@ -9,4 +9,4 @@ memory_limit = 50 interval = 10 [push] -endpoint = "http://[::1]:8081/push" +endpoint = "http://[::1]:8081/api.php?cmd=newmodmessages" diff --git a/theseus-server/src/main.rs b/theseus-server/src/main.rs index 757940f..e61c0b3 100644 --- a/theseus-server/src/main.rs +++ b/theseus-server/src/main.rs @@ -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>, ()> { 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, 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");