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 #workers=4
max_content_length="10MB" max_content_length="10MB"
upload_path="./upload" upload_path="./upload"
timeout="30s"
[paste] [paste]
random_url = { enabled = true, type = "petname", words = 2, separator = "-" } random_url = { enabled = true, type = "petname", words = 2, separator = "-" }

View file

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

View file

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