Skip to content

Commit 75a5a32

Browse files
committed
fix: also apply timeout to proxy requests
1 parent 80ab2d9 commit 75a5a32

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/lib/with_body.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse};
33
use app_state::AppState;
44
use futures::Future;
55
use proxy_transform::create_outgoing;
6+
use std::time::Duration;
67

78
///
89
/// This case handles incoming POST requests
@@ -11,16 +12,19 @@ use proxy_transform::create_outgoing;
1112
/// Note: This is not tested in any way with large uploads
1213
///
1314
pub fn forward_request_with_body(
14-
_req: &HttpRequest<AppState>,
15+
incoming_request: &HttpRequest<AppState>,
1516
req_target: String,
1617
mut outgoing: ClientRequestBuilder,
1718
) -> Box<Future<Item = HttpResponse, Error = Error>> {
18-
let next_target = _req.state().opts.target.clone();
19-
let output = _req.body().from_err().and_then(move |incoming_body| {
19+
let state = incoming_request.state();
20+
let timeout: u64 = state.opts.proxy_timeout_secs.into();
21+
let next_target = incoming_request.state().opts.target.clone();
22+
let output = incoming_request.body().from_err().and_then(move |incoming_body| {
2023
outgoing
2124
.body(incoming_body)
2225
.unwrap()
2326
.send()
27+
.timeout(Duration::from_secs(timeout))
2428
.map_err(Error::from)
2529
.and_then(move |proxy_response| {
2630
proxy_response

0 commit comments

Comments
 (0)