mirror of https://github.com/fafhrd91/actix-web
handle redirects without Location header
This commit is contained in:
parent
b1de196509
commit
8c1e8d0a83
|
@ -156,7 +156,7 @@ where
|
||||||
StatusCode::MOVED_PERMANENTLY
|
StatusCode::MOVED_PERMANENTLY
|
||||||
| StatusCode::FOUND
|
| StatusCode::FOUND
|
||||||
| StatusCode::SEE_OTHER
|
| StatusCode::SEE_OTHER
|
||||||
if *max_redirect_times > 0 =>
|
if *max_redirect_times > 0 && res.headers().contains_key(header::LOCATION) =>
|
||||||
{
|
{
|
||||||
let org_uri = uri.take().unwrap();
|
let org_uri = uri.take().unwrap();
|
||||||
// rebuild uri from the location header value.
|
// rebuild uri from the location header value.
|
||||||
|
@ -203,7 +203,7 @@ where
|
||||||
self.poll(cx)
|
self.poll(cx)
|
||||||
}
|
}
|
||||||
StatusCode::TEMPORARY_REDIRECT | StatusCode::PERMANENT_REDIRECT
|
StatusCode::TEMPORARY_REDIRECT | StatusCode::PERMANENT_REDIRECT
|
||||||
if *max_redirect_times > 0 =>
|
if *max_redirect_times > 0 && res.headers().contains_key(header::LOCATION) =>
|
||||||
{
|
{
|
||||||
let org_uri = uri.take().unwrap();
|
let org_uri = uri.take().unwrap();
|
||||||
// rebuild uri from the location header value.
|
// rebuild uri from the location header value.
|
||||||
|
@ -314,6 +314,30 @@ mod tests {
|
||||||
assert_eq!(res.status().as_u16(), 400);
|
assert_eq!(res.status().as_u16(), 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_redirect_without_location() {
|
||||||
|
let client = ClientBuilder::new()
|
||||||
|
.disable_redirects()
|
||||||
|
.wrap(Redirect::new().max_redirect_times(10))
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
let srv = actix_test::start(|| {
|
||||||
|
App::new()
|
||||||
|
.service(web::resource("/test").route(web::to(|| async {
|
||||||
|
Ok::<_, Error>(HttpResponse::BadRequest())
|
||||||
|
})))
|
||||||
|
.service(web::resource("/").route(web::to(|| async {
|
||||||
|
Ok::<_, Error>(
|
||||||
|
HttpResponse::Found().finish(),
|
||||||
|
)
|
||||||
|
})))
|
||||||
|
});
|
||||||
|
|
||||||
|
let res = client.get(srv.url("/")).send().await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(res.status().as_u16(), 302);
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_redirect_limit() {
|
async fn test_redirect_limit() {
|
||||||
let client = ClientBuilder::new()
|
let client = ClientBuilder::new()
|
||||||
|
|
Loading…
Reference in New Issue