Change config.url() to config.uri_parts() so that (later) path_and_query can be swapped out

This commit is contained in:
Mike Dilger 2024-11-18 08:30:30 +13:00
parent 3f26b47008
commit af1d992ce7
No known key found for this signature in database
GPG Key ID: 47581A78D4329BA4
3 changed files with 11 additions and 4 deletions

View File

@ -234,7 +234,7 @@ impl Default for Config {
}
impl Config {
pub fn url(&self, inner: Uri, http: bool) -> Result<Uri, Error> {
pub fn uri_parts(&self, inner: Uri, http: bool) -> Result<http::uri::Parts, Error> {
let mut uri_parts = inner.into_parts();
let scheme = match (self.use_tls, http) {
(false, false) => Scheme::from_str("ws").unwrap(),
@ -245,6 +245,6 @@ impl Config {
uri_parts.scheme = Some(scheme);
let authority = Authority::from_str(&format!("{}:{}", self.hostname, self.port))?;
uri_parts.authority = Some(authority);
Ok(Uri::from_parts(uri_parts)?)
Ok(uri_parts)
}
}

View File

@ -86,7 +86,11 @@ pub async fn check_auth(request: Request<Incoming>) -> Result<Value, Error> {
if let Some(u) = tags.get_value(b"u") {
let auth_url = String::from_utf8(u.to_owned())?;
let actual_url = {
let uri = GLOBALS.config.read().url(request.uri().to_owned(), true)?;
let uri_parts = GLOBALS
.config
.read()
.uri_parts(request.uri().to_owned(), true)?;
let uri = http::Uri::from_parts(uri_parts)?;
format!("{}", uri)
};

View File

@ -43,6 +43,8 @@ pub async fn serve_http(
}
}
let uri = request.uri().to_owned();
// Try blossom if enabled
if GLOBALS.config.read().blossom_directory.is_some() {
match blossom::handle(&request).await {
@ -55,7 +57,8 @@ pub async fn serve_http(
}
}
log::debug!(target: "Client", "{}: HTTP request for {}", peer, request.uri());
log::debug!(target: "Client", "{}: HTTP request for {}", peer, uri);
let response = Response::builder()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers", "*")