Commit unstaged changes
This commit is contained in:
parent
5672ff3d25
commit
32e4922c88
2 changed files with 21 additions and 7 deletions
|
|
@ -29,8 +29,8 @@ enum ConnCommand {
|
||||||
/// Configuration options for a [`ClientConn`].
|
/// Configuration options for a [`ClientConn`].
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ClientConnConfig {
|
pub struct ClientConnConfig {
|
||||||
/// The domain where the server is hosted.
|
/// The HTTP(S) url where the server is hosted.
|
||||||
pub domain: String,
|
pub url: String,
|
||||||
/// Whether the client should present itself as a human to the server.
|
/// Whether the client should present itself as a human to the server.
|
||||||
///
|
///
|
||||||
/// This should only be set if the client is directly acting on behalf of a
|
/// This should only be set if the client is directly acting on behalf of a
|
||||||
|
|
@ -53,7 +53,7 @@ pub struct ClientConnConfig {
|
||||||
impl Default for ClientConnConfig {
|
impl Default for ClientConnConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
domain: "euphoria.leet.nu".to_string(),
|
url: "https://euphoria.leet.nu/".to_string(),
|
||||||
human: false,
|
human: false,
|
||||||
channel_bufsize: 10,
|
channel_bufsize: 10,
|
||||||
connect_timeout: Duration::from_secs(10),
|
connect_timeout: Duration::from_secs(10),
|
||||||
|
|
@ -211,14 +211,24 @@ impl ClientConn {
|
||||||
room: &str,
|
room: &str,
|
||||||
cookies: Option<HeaderValue>,
|
cookies: Option<HeaderValue>,
|
||||||
config: &ClientConnConfig,
|
config: &ClientConnConfig,
|
||||||
) -> Result<(Self, Vec<HeaderValue>)> {
|
|
||||||
// Prepare URL
|
// Prepare URL
|
||||||
|
) -> Result<(Self, Vec<HeaderValue>)> {
|
||||||
let human = if config.human { "?h=1" } else { "" };
|
let human = if config.human { "?h=1" } else { "" };
|
||||||
let uri = format!("wss://{}/room/{room}/ws{human}", config.domain);
|
|
||||||
debug!("Connecting to {uri} with cookies: {cookies:?}");
|
if !(config.url.starts_with("http://") || config.url.starts_with("https://")) {
|
||||||
|
return Err(Error::InvalidUrl);
|
||||||
|
};
|
||||||
|
let prepared_url = config
|
||||||
|
.url
|
||||||
|
.strip_prefix("http")
|
||||||
|
.ok_or(Error::InvalidUrl)?
|
||||||
|
.trim_end_matches('/');
|
||||||
|
|
||||||
|
let ws_url = format!("ws{prepared_url}/room/{room}/ws{human}");
|
||||||
|
debug!("Connecting to {ws_url} with cookies: {cookies:?}");
|
||||||
|
|
||||||
// Prepare request
|
// Prepare request
|
||||||
let mut request = uri.into_client_request().expect("valid request");
|
let mut request = ws_url.into_client_request().expect("valid request");
|
||||||
if let Some(cookies) = cookies {
|
if let Some(cookies) = cookies {
|
||||||
request.headers_mut().append(header::COOKIE, cookies);
|
request.headers_mut().append(header::COOKIE, cookies);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ use crate::api::PacketType;
|
||||||
/// Possible euphoria communication errors.
|
/// Possible euphoria communication errors.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
/// The URL has an invalid format.
|
||||||
|
InvalidUrl,
|
||||||
|
|
||||||
/// The connection is closed.
|
/// The connection is closed.
|
||||||
ConnectionClosed,
|
ConnectionClosed,
|
||||||
|
|
||||||
|
|
@ -54,6 +57,7 @@ pub enum Error {
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
Self::InvalidUrl => write!(f, "url has invalid format"),
|
||||||
Self::ConnectionClosed => write!(f, "connection closed"),
|
Self::ConnectionClosed => write!(f, "connection closed"),
|
||||||
Self::PingTimeout => write!(f, "ping timed out"),
|
Self::PingTimeout => write!(f, "ping timed out"),
|
||||||
Self::MalformedPacket(err) => write!(f, "malformed packet: {err}"),
|
Self::MalformedPacket(err) => write!(f, "malformed packet: {err}"),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue