mirror of https://github.com/fafhrd91/actix-web
client redirects only handled when location header present
closes #2105
This commit is contained in:
parent
4b3d0edc9e
commit
f983103e44
|
@ -161,7 +161,8 @@ where
|
|||
| StatusCode::SEE_OTHER
|
||||
| StatusCode::TEMPORARY_REDIRECT
|
||||
| StatusCode::PERMANENT_REDIRECT
|
||||
if *max_redirect_times > 0 =>
|
||||
if *max_redirect_times > 0
|
||||
&& res.headers().contains_key(header::LOCATION) =>
|
||||
{
|
||||
let reuse_body = res.head().status == StatusCode::TEMPORARY_REDIRECT
|
||||
|| res.head().status == StatusCode::PERMANENT_REDIRECT;
|
||||
|
@ -287,7 +288,10 @@ mod tests {
|
|||
use actix_web::{web, App, Error, HttpRequest, HttpResponse};
|
||||
|
||||
use super::*;
|
||||
use crate::{http::header::HeaderValue, ClientBuilder};
|
||||
use crate::{
|
||||
http::{header::HeaderValue, StatusCode},
|
||||
ClientBuilder,
|
||||
};
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_basic_redirect() {
|
||||
|
@ -315,6 +319,23 @@ mod tests {
|
|||
assert_eq!(res.status().as_u16(), 400);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn 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("/").route(web::to(|| async {
|
||||
Ok::<_, Error>(HttpResponse::Found().finish())
|
||||
})))
|
||||
});
|
||||
|
||||
let res = client.get(srv.url("/")).send().await.unwrap();
|
||||
assert_eq!(res.status(), StatusCode::FOUND);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_redirect_limit() {
|
||||
let client = ClientBuilder::new()
|
||||
|
@ -328,14 +349,14 @@ mod tests {
|
|||
.service(web::resource("/").route(web::to(|| async {
|
||||
Ok::<_, Error>(
|
||||
HttpResponse::Found()
|
||||
.append_header(("location", "/test"))
|
||||
.insert_header(("location", "/test"))
|
||||
.finish(),
|
||||
)
|
||||
})))
|
||||
.service(web::resource("/test").route(web::to(|| async {
|
||||
Ok::<_, Error>(
|
||||
HttpResponse::Found()
|
||||
.append_header(("location", "/test2"))
|
||||
.insert_header(("location", "/test2"))
|
||||
.finish(),
|
||||
)
|
||||
})))
|
||||
|
@ -345,8 +366,15 @@ mod tests {
|
|||
});
|
||||
|
||||
let res = client.get(srv.url("/")).send().await.unwrap();
|
||||
|
||||
assert_eq!(res.status().as_u16(), 302);
|
||||
assert_eq!(res.status(), StatusCode::FOUND);
|
||||
assert_eq!(
|
||||
res.headers()
|
||||
.get(header::LOCATION)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"/test2"
|
||||
);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
|
|
Loading…
Reference in New Issue