From 75a5a324b71e217d9c8bd16f83e4bdafb334f0c4 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Tue, 27 Nov 2018 09:59:47 +0100 Subject: [PATCH] fix: also apply timeout to proxy requests --- src/lib/with_body.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/with_body.rs b/src/lib/with_body.rs index c813979..ceff390 100644 --- a/src/lib/with_body.rs +++ b/src/lib/with_body.rs @@ -3,6 +3,7 @@ use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse}; use app_state::AppState; use futures::Future; use proxy_transform::create_outgoing; +use std::time::Duration; /// /// This case handles incoming POST requests @@ -11,16 +12,19 @@ use proxy_transform::create_outgoing; /// Note: This is not tested in any way with large uploads /// pub fn forward_request_with_body( - _req: &HttpRequest, + incoming_request: &HttpRequest, req_target: String, mut outgoing: ClientRequestBuilder, ) -> Box> { - let next_target = _req.state().opts.target.clone(); - let output = _req.body().from_err().and_then(move |incoming_body| { + let state = incoming_request.state(); + let timeout: u64 = state.opts.proxy_timeout_secs.into(); + let next_target = incoming_request.state().opts.target.clone(); + let output = incoming_request.body().from_err().and_then(move |incoming_body| { outgoing .body(incoming_body) .unwrap() .send() + .timeout(Duration::from_secs(timeout)) .map_err(Error::from) .and_then(move |proxy_response| { proxy_response