feat(config): support setting the timeout for HTTP requests

This commit is contained in:
Orhun Parmaksız 2022-03-12 00:35:54 +03:00
parent fda6f91211
commit 94516c95bb
No known key found for this signature in database
GPG Key ID: F83424824B3E4B90
3 changed files with 9 additions and 1 deletions

View File

@ -6,6 +6,7 @@ address="127.0.0.1:8000"
#workers=4
max_content_length="10MB"
upload_path="./upload"
timeout="30s"
[paste]
random_url = { enabled = true, type = "petname", words = 2, separator = "-" }

View File

@ -35,6 +35,9 @@ pub struct ServerConfig {
pub max_content_length: Byte,
/// Storage path.
pub upload_path: PathBuf,
/// Request timeout.
#[serde(default, with = "humantime_serde")]
pub timeout: Option<Duration>,
/// Authentication token.
pub auth_token: Option<String>,
}

View File

@ -68,7 +68,11 @@ async fn main() -> IoResult<()> {
// Create a HTTP server.
let mut http_server = HttpServer::new(move || {
let http_client = ClientBuilder::default()
.timeout(Duration::from_secs(30))
.timeout(
server_config
.timeout
.unwrap_or_else(|| Duration::from_secs(30)),
)
.disable_redirects()
.finish();
App::new()