Use basic auth in publish requests

Fixes #12
This commit is contained in:
ranfdev
2023-11-27 18:58:01 +01:00
parent 80154cace8
commit 7d86e9598a

View File

@ -202,11 +202,16 @@ impl SubscriptionImpl {
fn _publish<'a>(&'a mut self, msg: &'a str) -> impl Future<Output = Result<(), capnp::Error>> {
let msg = msg.to_owned();
let req = self.env.http.post(&self.model.borrow().server).body(msg);
let server = &self.model.borrow().server;
let creds = self.env.credentials.get(server);
let mut req = self.env.http.post(server);
if let Some(creds) = creds {
req = req.basic_auth(creds.username, Some(creds.password));
}
async move {
info!("sending message");
let res = req.send().await;
let res = req.body(msg).send().await;
match res {
Err(e) => Err(capnp::Error::failed(e.to_string())),
Ok(res) => {