Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Redirecting /home to new UI #3084

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dapps/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ impl<A: Authorization + 'static> server::Handler<HttpStream> for Router<A> {
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,
Expand All @@ -116,7 +120,7 @@ impl<A: Authorization + 'static> server::Handler<HttpStream> for Router<A> {
))
},
// 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)))
Expand Down
20 changes: 20 additions & 0 deletions dapps/src/tests/redirection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down