From a192e9baca9a14beaa9f87c27a63cff96aa41c94 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sun, 25 Feb 2024 20:00:38 +0100 Subject: Closes #4. Auth on Websocket. Small stuff --- src/requests/start.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/requests/start.rs') diff --git a/src/requests/start.rs b/src/requests/start.rs index 7abbbe0..d07177e 100644 --- a/src/requests/start.rs +++ b/src/requests/start.rs @@ -2,7 +2,10 @@ use futures_util::{SinkExt, StreamExt}; use indicatif::{MultiProgress, ProgressBar}; use reqwest::StatusCode; use serde::Deserialize; -use tokio_tungstenite::{connect_async, tungstenite::Message}; +use tokio_tungstenite::{ + connect_async, + tungstenite::{http::Request, Message}, +}; use crate::{ add_pb, config::Config, default_headers, error::Error, finish_pb, format_url, ErrorResponse, @@ -66,17 +69,26 @@ async fn status_socket( id: String, ) -> Result { let ws_pb = add_pb(pb, DEFAULT_STYLE, "connect to websocket".to_string()); - let (mut ws_stream, _response) = - connect_async(format_url(config, "status", &Protocols::Websocket)) - .await - .expect("Failed to connect"); + + let request = Request::builder() + .uri(format_url(config, "status", &Protocols::Websocket)) + .header("Authorization", &config.apikey) + .header("sec-websocket-key", "") + .header("host", &config.server) + .header("upgrade", "websocket") + .header("connection", "upgrade") + .header("sec-websocket-version", 13) + .body(()) + .unwrap(); + + let (mut ws_stream, _response) = connect_async(request).await?; finish_pb(&ws_pb, "connected to websocket".to_string(), DONE_STYLE); ws_stream.send(Message::Text(uuid.clone())).await.unwrap(); // Get ETA let eta_msg = ws_stream.next().await.unwrap().unwrap(); - let eta = get_eta(&eta_msg.into_text().unwrap(), &uuid)? + overview.elapsed().as_secs(); + let eta = get_eta(&eta_msg.into_text().unwrap(), &uuid)?; overview.set_message(format!("/{eta}) start {id}")); let msg_pb = add_pb(pb, DEFAULT_STYLE, "await message".to_string()); -- cgit v1.2.3