From 88e6b6ac6c5863e73ce6d24d952c345344a2d116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Wed, 2 Nov 2016 09:22:49 +0100 Subject: [PATCH] Redirecting /home to new UI --- dapps/src/router/mod.rs | 8 ++++++-- dapps/src/tests/redirection.rs | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dapps/src/router/mod.rs b/dapps/src/router/mod.rs index ff60df99619..6ca453d6dda 100644 --- a/dapps/src/router/mod.rs +++ b/dapps/src/router/mod.rs @@ -105,8 +105,12 @@ impl server::Handler for Router { trace!(target: "dapps", "Resolving to fetchable content."); self.fetch.to_async_handler(path.clone(), control) }, + // NOTE [todr] /home is redirected to home page since some users may have the redirection cached + // (in the past we used 301 instead of 302) + // It should be safe to remove it in (near) future. + // // 404 for non-existent content - (Some(_), _) if *req.method() == hyper::method::Method::Get => { + (Some(ref path), _) if *req.method() == hyper::Method::Get && path.app_id != "home" => { trace!(target: "dapps", "Resolving to 404."); Box::new(ContentHandler::error( StatusCode::NotFound, @@ -116,7 +120,7 @@ impl server::Handler for Router { )) }, // Redirect any other GET request to signer. - _ if *req.method() == hyper::method::Method::Get => { + _ if *req.method() == hyper::Method::Get => { if let Some(port) = self.signer_port { trace!(target: "dapps", "Redirecting to signer interface."); Redirection::boxed(&format!("http://{}", signer_address(port))) diff --git a/dapps/src/tests/redirection.rs b/dapps/src/tests/redirection.rs index aee1cb964c7..398d08774e7 100644 --- a/dapps/src/tests/redirection.rs +++ b/dapps/src/tests/redirection.rs @@ -56,6 +56,26 @@ fn should_redirect_to_home_when_trailing_slash_is_missing() { assert_eq!(response.headers.get(0).unwrap(), "Location: http://127.0.0.1:18180"); } +#[test] +fn should_redirect_to_home_for_users_with_cached_redirection() { + // given + let server = serve(); + + // when + let response = request(server, + "\ + GET /home/ HTTP/1.1\r\n\ + Host: 127.0.0.1:8080\r\n\ + Connection: close\r\n\ + \r\n\ + " + ); + + // then + assert_eq!(response.status, "HTTP/1.1 302 Found".to_owned()); + assert_eq!(response.headers.get(0).unwrap(), "Location: http://127.0.0.1:18180"); +} + #[test] fn should_display_404_on_invalid_dapp() { // given