Skip to content

Commit 16a9ab9

Browse files
hipstermojoFishrock123
authored andcommitted
Add fix for redirect middleware for #276
1 parent 5a5621b commit 16a9ab9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/middleware/redirect/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,24 @@ impl Middleware for Redirect {
9191
// and try sending it until we get some status back that is not a
9292
// redirect.
9393

94+
let base_url = req.url().clone();
95+
9496
while redirect_count < self.attempts {
9597
redirect_count += 1;
9698
let r: Request = req.clone();
9799
let res: Response = client.send(r).await?;
98100
if REDIRECT_CODES.contains(&res.status()) {
99101
if let Some(location) = res.header(headers::LOCATION) {
100102
let http_req: &mut http::Request = req.as_mut();
101-
*http_req.url_mut() = Url::parse(location.last().as_str())?;
103+
*http_req.url_mut() = match Url::parse(location.last().as_str()) {
104+
Ok(valid_url) => valid_url,
105+
Err(e) => match e {
106+
http::url::ParseError::RelativeUrlWithoutBase => {
107+
base_url.join(location.last().as_str())?
108+
}
109+
e => return Err(e.into()),
110+
},
111+
};
102112
}
103113
} else {
104114
break;

0 commit comments

Comments
 (0)