Skip to content

Commit 7e2731f

Browse files
committed
Redirect to / when accessed to /history
1 parent 42f01e3 commit 7e2731f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ class HistoryServer(
7676
// attempt ID (separated by a slash).
7777
val parts = Option(req.getPathInfo()).getOrElse("").split("/")
7878
if (parts.length < 2) {
79-
res.sendError(HttpServletResponse.SC_BAD_REQUEST,
80-
s"Unexpected path info in request (URI = ${req.getRequestURI()}")
81-
return
79+
res.sendRedirect("/")
8280
}
8381

8482
val appId = parts(1)

core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,19 @@ class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with Matchers
644644
val actualContentType = conn.getContentType
645645
assert(actualContentType === expectedContentType)
646646
}
647+
648+
test("Redirect to the root page when accessed to /history/") {
649+
val port = server.boundPort
650+
val url = new URL(s"http://localhost:$port/history/")
651+
val conn = url.openConnection().asInstanceOf[HttpURLConnection]
652+
conn.setRequestMethod("GET")
653+
conn.setUseCaches(false)
654+
conn.setDefaultUseCaches(false)
655+
conn.setInstanceFollowRedirects(false)
656+
conn.connect()
657+
assert(conn.getResponseCode === 302)
658+
assert(conn.getHeaderField("Location") === s"http://localhost:$port/")
659+
}
647660
}
648661

649662
object HistoryServerSuite {

0 commit comments

Comments
 (0)