diff --git a/src/config.rs b/src/config.rs index ca0aec0..9fe9455 100644 --- a/src/config.rs +++ b/src/config.rs @@ -30,6 +30,8 @@ pub struct Settings { pub struct ServerConfig { /// The socket address to bind. pub address: String, + /// URL that can be used to access the server externally. + pub url: Option, /// Number of workers to start. pub workers: Option, /// Maximum content length. diff --git a/src/server.rs b/src/server.rs index 7993562..39a2c2f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -137,6 +137,18 @@ async fn upload( ) -> Result { let connection = request.connection_info().clone(); let host = connection.peer_addr().unwrap_or("unknown host"); + let server_url = match config + .read() + .map_err(|_| error::ErrorInternalServerError("cannot acquire config"))? + .server + .url + .clone() + { + Some(v) => v, + None => { + format!("{}://{}", connection.scheme(), connection.host(),) + } + }; auth::check( host, request.headers(), @@ -187,9 +199,8 @@ async fn upload( .get_file(bytes_checksum) { urls.push(format!( - "{}://{}/{}\n", - connection.scheme(), - connection.host(), + "{}/{}\n", + server_url, file.path .file_name() .map(|v| v.to_string_lossy()) @@ -227,12 +238,7 @@ async fn upload( Byte::from_bytes(paste.data.len() as u128).get_appropriate_unit(false), host ); - urls.push(format!( - "{}://{}/{}\n", - connection.scheme(), - connection.host(), - file_name - )); + urls.push(format!("{}/{}\n", server_url, file_name)); } else { log::warn!("{} sent an invalid form field", host); return Err(error::ErrorBadRequest("invalid form field"));