fix host spoofing for redirects
This commit is contained in:
@@ -148,18 +148,16 @@ impl Request {
|
||||
|
||||
let request_fn = |req: Request| {
|
||||
let reader = payload.into_read();
|
||||
let mut unit = Unit::new(
|
||||
let unit = Unit::new(
|
||||
&req.agent,
|
||||
&req.method,
|
||||
&url,
|
||||
req.headers,
|
||||
&reader,
|
||||
deadline,
|
||||
req.spoofed_host
|
||||
);
|
||||
|
||||
// forward the spoofed host address
|
||||
unit.spoofed_host = req.spoofed_host;
|
||||
|
||||
unit::connect(unit, true, reader).map_err(|e| e.url(url.clone()))
|
||||
};
|
||||
|
||||
|
||||
@@ -767,6 +767,7 @@ impl FromStr for Response {
|
||||
vec![],
|
||||
&request_reader,
|
||||
None,
|
||||
None
|
||||
);
|
||||
Self::do_from_stream(stream, unit)
|
||||
}
|
||||
@@ -1151,6 +1152,7 @@ mod tests {
|
||||
vec![],
|
||||
&request_reader,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
let resp = Response::do_from_stream(s.into(), unit).unwrap();
|
||||
assert_eq!(resp.status(), 200);
|
||||
@@ -1215,6 +1217,7 @@ mod tests {
|
||||
vec![],
|
||||
&Payload::Empty.into_read(),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1247,6 +1250,7 @@ mod tests {
|
||||
vec![],
|
||||
&Payload::Empty.into_read(),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -46,8 +46,8 @@ impl Unit {
|
||||
mut headers: Vec<Header>,
|
||||
body: &SizedReader,
|
||||
deadline: Option<time::Instant>,
|
||||
spoofed_host: Option<Cow<'static, str>>,
|
||||
) -> Self {
|
||||
//
|
||||
|
||||
let (is_transfer_encoding_set, mut is_chunked) = get_header(&headers, "transfer-encoding")
|
||||
// if the user has set an encoding header, obey that.
|
||||
@@ -110,7 +110,7 @@ impl Unit {
|
||||
is_chunked,
|
||||
headers,
|
||||
deadline,
|
||||
spoofed_host: None,
|
||||
spoofed_host,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,6 +227,8 @@ pub(crate) fn connect(
|
||||
&& (!h.is_name("authorization") || keep_auth_header)
|
||||
});
|
||||
|
||||
|
||||
|
||||
// recreate the unit to get a new hostname and cookies for the new host.
|
||||
unit = Unit::new(
|
||||
&unit.agent,
|
||||
@@ -235,6 +237,7 @@ pub(crate) fn connect(
|
||||
headers,
|
||||
&body,
|
||||
unit.deadline,
|
||||
unit.spoofed_host
|
||||
);
|
||||
};
|
||||
resp.history = history;
|
||||
|
||||
Reference in New Issue
Block a user