cargo fmt

This commit is contained in:
Omid Rad 2021-07-12 14:36:54 +02:00
parent 8b022b7071
commit 3125db2944
1 changed files with 25 additions and 28 deletions

View File

@ -158,7 +158,9 @@ where
connector, connector,
} => match ready!(fut.poll(cx))? { } => match ready!(fut.poll(cx))? {
ConnectResponse::Client(res) => match res.head().status { ConnectResponse::Client(res) => match res.head().status {
status @ (StatusCode::MOVED_PERMANENTLY status
@
(StatusCode::MOVED_PERMANENTLY
| StatusCode::FOUND | StatusCode::FOUND
| StatusCode::SEE_OTHER | StatusCode::SEE_OTHER
| StatusCode::TEMPORARY_REDIRECT | StatusCode::TEMPORARY_REDIRECT
@ -166,9 +168,11 @@ where
if *max_redirect_times > 0 => if *max_redirect_times > 0 =>
{ {
let is_redirect = match status { let is_redirect = match status {
StatusCode::TEMPORARY_REDIRECT | StatusCode::PERMANENT_REDIRECT => true, StatusCode::TEMPORARY_REDIRECT | StatusCode::PERMANENT_REDIRECT => {
_ => false true
}; }
_ => false,
};
let prev_uri = uri.take().unwrap(); let prev_uri = uri.take().unwrap();
@ -273,7 +277,8 @@ fn build_next_uri(res: &ClientResponse, prev_uri: &Uri) -> Result<Uri, SendReque
fn remove_sensitive_headers(headers: &mut header::HeaderMap, prev_uri: &Uri, next_uri: &Uri) { fn remove_sensitive_headers(headers: &mut header::HeaderMap, prev_uri: &Uri, next_uri: &Uri) {
if next_uri.host() != prev_uri.host() if next_uri.host() != prev_uri.host()
|| next_uri.port() != prev_uri.port() || next_uri.port() != prev_uri.port()
|| next_uri.scheme() != prev_uri.scheme() { || next_uri.scheme() != prev_uri.scheme()
{
headers.remove(header::AUTHORIZATION); headers.remove(header::AUTHORIZATION);
headers.remove(header::WWW_AUTHENTICATE); headers.remove(header::WWW_AUTHENTICATE);
headers.remove(header::COOKIE); headers.remove(header::COOKIE);
@ -411,31 +416,26 @@ mod tests {
// defining two services to have two different origins // defining two services to have two different origins
let srv2 = actix_test::start(|| { let srv2 = actix_test::start(|| {
async fn root(req: HttpRequest) -> HttpResponse { async fn root(req: HttpRequest) -> HttpResponse {
if req.headers() if req.headers().get(header::AUTHORIZATION).is_none() {
.get(header::AUTHORIZATION)
.is_none()
{
HttpResponse::Ok().finish() HttpResponse::Ok().finish()
} else { } else {
HttpResponse::InternalServerError().finish() HttpResponse::InternalServerError().finish()
} }
} }
App::new() App::new().service(web::resource("/").route(web::to(root)))
.service(web::resource("/").route(web::to(root)))
}); });
let srv2_port: u16 = srv2.addr().port(); let srv2_port: u16 = srv2.addr().port();
let srv1 = actix_test::start(move || { let srv1 = actix_test::start(move || {
async fn root(req: HttpRequest) -> HttpResponse { async fn root(req: HttpRequest) -> HttpResponse {
let port = *req.app_data::<u16>().unwrap(); let port = *req.app_data::<u16>().unwrap();
if req if req.headers().get(header::AUTHORIZATION).is_some() {
.headers()
.get(header::AUTHORIZATION)
.is_some()
{
HttpResponse::Found() HttpResponse::Found()
.append_header(("location", format!("http://localhost:{}/", port).as_str())) .append_header((
"location",
format!("http://localhost:{}/", port).as_str(),
))
.finish() .finish()
} else { } else {
HttpResponse::InternalServerError().finish() HttpResponse::InternalServerError().finish()
@ -443,11 +443,7 @@ mod tests {
} }
async fn test1(req: HttpRequest) -> HttpResponse { async fn test1(req: HttpRequest) -> HttpResponse {
if req if req.headers().get(header::AUTHORIZATION).is_some() {
.headers()
.get(header::AUTHORIZATION)
.is_some()
{
HttpResponse::Found() HttpResponse::Found()
.append_header(("location", "/test2")) .append_header(("location", "/test2"))
.finish() .finish()
@ -457,10 +453,7 @@ mod tests {
} }
async fn test2(req: HttpRequest) -> HttpResponse { async fn test2(req: HttpRequest) -> HttpResponse {
if req.headers() if req.headers().get(header::AUTHORIZATION).is_some() {
.get(header::AUTHORIZATION)
.is_some()
{
HttpResponse::Ok().finish() HttpResponse::Ok().finish()
} else { } else {
HttpResponse::InternalServerError().finish() HttpResponse::InternalServerError().finish()
@ -475,12 +468,16 @@ mod tests {
}); });
// send a request to different origins, http://srv1/ then http://srv2/. So it should remove the header // send a request to different origins, http://srv1/ then http://srv2/. So it should remove the header
let client = ClientBuilder::new().header(header::AUTHORIZATION, "auth_key_value").finish(); let client = ClientBuilder::new()
.header(header::AUTHORIZATION, "auth_key_value")
.finish();
let res = client.get(srv1.url("/")).send().await.unwrap(); let res = client.get(srv1.url("/")).send().await.unwrap();
assert_eq!(res.status().as_u16(), 200); assert_eq!(res.status().as_u16(), 200);
// send a request to same origin, http://srv1/test1 then http://srv1/test2. So it should NOT remove any header // send a request to same origin, http://srv1/test1 then http://srv1/test2. So it should NOT remove any header
let client = ClientBuilder::new().header(header::AUTHORIZATION, "auth_key_value").finish(); let client = ClientBuilder::new()
.header(header::AUTHORIZATION, "auth_key_value")
.finish();
let res = client.get(srv1.url("/test1")).send().await.unwrap(); let res = client.get(srv1.url("/test1")).send().await.unwrap();
assert_eq!(res.status().as_u16(), 200); assert_eq!(res.status().as_u16(), 200);
} }