prepare for peehaitchpee
This commit is contained in:
@@ -9,4 +9,4 @@ memory_limit = 50
|
|||||||
interval = 10
|
interval = 10
|
||||||
|
|
||||||
[push]
|
[push]
|
||||||
endpoint = "http://[::1]:8081/push"
|
endpoint = "http://[::1]:8081/api.php?cmd=newmodmessages"
|
||||||
|
@@ -202,6 +202,7 @@ struct PushEndpoint<'a> {
|
|||||||
port: u16,
|
port: u16,
|
||||||
addr: String,
|
addr: String,
|
||||||
authority: String,
|
authority: String,
|
||||||
|
path_and_query: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PushEndpoint<'a> {
|
impl<'a> PushEndpoint<'a> {
|
||||||
@@ -210,7 +211,12 @@ impl<'a> PushEndpoint<'a> {
|
|||||||
let port = uri.port_u16().ok_or("no port provided")?;
|
let port = uri.port_u16().ok_or("no port provided")?;
|
||||||
let addr = format!("{}:{}", host, port);
|
let addr = format!("{}:{}", host, port);
|
||||||
let authority = uri.authority().ok_or("no authority provided")?.to_string();
|
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>>, ()> {
|
) -> Result<hyper::Request<Full<Bytes>>, ()> {
|
||||||
let Ok(body) = serde_json::to_string(questions) else { return Err(()); };
|
let Ok(body) = serde_json::to_string(questions) else { return Err(()); };
|
||||||
hyper::Request::builder()
|
hyper::Request::builder()
|
||||||
.uri(uri.uri)
|
.uri(&uri.path_and_query)
|
||||||
|
.method(hyper::Method::POST)
|
||||||
.header(hyper::header::HOST, &uri.authority)
|
.header(hyper::header::HOST, &uri.authority)
|
||||||
.header(hyper::header::CONTENT_TYPE, "application/json")
|
.header(hyper::header::CONTENT_TYPE, "application/json")
|
||||||
.body(Full::new(Bytes::from(body))).map_err(|_| ())
|
.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");
|
log!(err "could not construct push questions request");
|
||||||
return Err(());
|
return Err(());
|
||||||
};
|
};
|
||||||
let Ok(res) = conn.send_request(req).await else {
|
let res = match conn.send_request(req).await {
|
||||||
log!(err "could not send questions request to push endpoint");
|
Ok(v) => v,
|
||||||
return Err(());
|
Err(e) => {
|
||||||
|
log!(err "could not send questions request to push endpoint: {:?}", e);
|
||||||
|
return Err(());
|
||||||
|
},
|
||||||
};
|
};
|
||||||
if res.status() != hyper::StatusCode::OK {
|
if res.status() != hyper::StatusCode::OK {
|
||||||
log!(err "got non-200 response from push endpoint");
|
log!(err "got non-200 response from push endpoint");
|
||||||
|
Reference in New Issue
Block a user