Skip to content

Commit

Permalink
Post urgent=true to endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Nov 11, 2023
1 parent 8984e33 commit 1179772
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/utils/post_allowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use async_trait::async_trait;
use eyre::{eyre, Result};
use lazy_static::lazy_static;
use reqwest::redirect::Policy;
use serde::Serialize;
use std::{
error::Error as StdError,
fmt::{Display, Formatter},
Expand Down Expand Up @@ -30,7 +31,7 @@ impl Display for Error {

impl StdError for Error {}

pub async fn post_allowed(url: Url, body: &[(&str, &str)]) -> Result<reqwest::Response> {
pub async fn post_allowed<T: Serialize + ?Sized>(url: Url, body: &T) -> Result<reqwest::Response> {
let port = match url.port() {
Some(p) => p,
None if url.scheme() == "http" => 80,
Expand Down Expand Up @@ -114,6 +115,8 @@ impl ResolveAllowed for LookupIp {

#[cfg(test)]
mod tests {
use rocket::serde::json::serde_json::json;

use super::*;
use std::str::FromStr;

Expand All @@ -129,8 +132,8 @@ mod tests {
#[tokio::test]
async fn test_post() {
post_allowed(
Url::from_str("https://httpbin.org/post").unwrap(),
&[("foo", "blah")],
Url::from_str("http://127.0.0.1:8088").unwrap(),
&json!({"urgent": true}),
)
.await
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/ws/signalwebsocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use async_trait::async_trait;
use eyre::Result;
use futures_channel::mpsc;
use prost::Message;
use rocket::serde::json::serde_json::json;
use std::{
sync::{Arc, Mutex},
time::{Duration, Instant},
Expand Down Expand Up @@ -231,7 +232,7 @@ impl SignalWebSocket {
}

let url = self.push_endpoint.clone();
let _ = post_allowed(url, &[("type", "message")]).await;
let _ = post_allowed(url, &json!({"urgent": true})).await;
if let Some(tx) = &self.channels.on_push_tx {
let _ = tx.unbounded_send(1);
}
Expand Down

0 comments on commit 1179772

Please sign in to comment.