File tree 1 file changed +11
-1
lines changed 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -91,14 +91,24 @@ impl Middleware for Redirect {
91
91
// and try sending it until we get some status back that is not a
92
92
// redirect.
93
93
94
+ let base_url = req. url ( ) . clone ( ) ;
95
+
94
96
while redirect_count < self . attempts {
95
97
redirect_count += 1 ;
96
98
let r: Request = req. clone ( ) ;
97
99
let res: Response = client. send ( r) . await ?;
98
100
if REDIRECT_CODES . contains ( & res. status ( ) ) {
99
101
if let Some ( location) = res. header ( headers:: LOCATION ) {
100
102
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
+ } ;
102
112
}
103
113
} else {
104
114
break ;
You can’t perform that action at this time.
0 commit comments