Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
sendRedirect does always specify the host.
Browse files Browse the repository at this point in the history
use a separate method for that.

(cherry picked from commit 82837be)
  • Loading branch information
aquamatthias authored and gkleiman committed Sep 24, 2015
1 parent e8de564 commit 163858e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/main/scala/mesosphere/marathon/api/WebJarServlet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class WebJarServlet extends HttpServlet {
}

//special rule for accessing root -> redirect to ui main page
if (req.getRequestURI == "/") resp.sendRedirect("/ui/")
if (req.getRequestURI == "/") sendRedirect(resp, "/ui/")
//if a directory is requested, redirect to trailing slash
else if (!file.contains(".")) resp.sendRedirect(req.getRequestURI + "/") //request /ui -> /ui/
else if (!file.contains(".")) sendRedirect(resp, req.getRequestURI + "/") //request /ui -> /ui/
//if we come here, it must be a resource
else sendResourceNormalized(resourceURI, mime)
}
Expand All @@ -73,4 +73,9 @@ class WebJarServlet extends HttpServlet {
case _ => "application/octet-stream"
}
}

private[this] def sendRedirect(response: HttpServletResponse, location: String): Unit = {
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY)
response.setHeader("Location", location)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class WebJarServletTest extends MarathonSpec with Mockito with GivenWhenThen wit
servlet.doGet(request, response)

Then("A redirect response is send")
verify(response, atLeastOnce).sendRedirect("/ui/")
verify(response, atLeastOnce).setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY)
verify(response, atLeastOnce).setHeader("Location", "/ui/")
}

test("Get a directory without leading / will send a redirect") {
Expand All @@ -32,7 +33,8 @@ class WebJarServletTest extends MarathonSpec with Mockito with GivenWhenThen wit
servlet.doGet(request, response)

Then("A redirect response is send")
verify(response, atLeastOnce).sendRedirect("/some/directory/")
verify(response, atLeastOnce).setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY)
verify(response, atLeastOnce).setHeader("Location", "/some/directory/")
}

test("Get a non existing path will return 404"){
Expand Down

0 comments on commit 163858e

Please sign in to comment.