Skip to content

Commit

Permalink
taxy-api: fix a build issue on wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
picoHz committed Aug 14, 2024
1 parent b9bf70c commit 77201e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 5 additions & 9 deletions taxy-api/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::fmt;
use std::str::FromStr;

use crate::error::Error;
use crate::subject_name::SubjectName;
use crate::{id::ShortId, port::UpstreamServer};
use serde_default::DefaultFromSerde;
use serde_derive::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;
use url::Url;
use utoipa::ToSchema;
use warp::filters::host::Authority;

#[derive(Debug, DefaultFromSerde, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
pub struct Proxy {
Expand Down Expand Up @@ -118,14 +116,12 @@ impl ServerUrl {
self.0.host_str()
}

pub fn authority(&self) -> Option<Authority> {
format!(
pub fn authority(&self) -> Option<String> {
Some(format!(
"{}:{}",
self.hostname()?,
self.0.port_or_known_default().unwrap_or_default()
)
.parse()
.ok()
))
}
}

Expand Down
8 changes: 6 additions & 2 deletions taxy/src/proxy/http/route.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::filter::{FilterResult, RequestFilter};
use hyper::Request;
use std::str::FromStr;
use taxy_api::{
error::Error,
id::ShortId,
Expand Down Expand Up @@ -88,15 +89,18 @@ impl TryFrom<Server> for ParsedServer {
type Error = Error;

fn try_from(server: Server) -> Result<Self, Self::Error> {
let url = server.url.clone().into();
let authority = server.url.authority().ok_or(Error::InvalidServerUrl {
url: server.url.to_string(),
})?;
let hostname = server.url.hostname().ok_or(Error::InvalidServerUrl {
url: server.url.to_string(),
})?;
Ok(Self {
url: server.url.into(),
authority,
url,
authority: Authority::from_str(&authority).map_err(|_| Error::InvalidServerUrl {
url: hostname.to_owned(),
})?,
})
}
}

0 comments on commit 77201e8

Please sign in to comment.