diff --git a/core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala b/core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala index aa9e9a6dd4887..ca21a8056d1b5 100644 --- a/core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala +++ b/core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala @@ -76,9 +76,7 @@ class HistoryServer( // attempt ID (separated by a slash). val parts = Option(req.getPathInfo()).getOrElse("").split("/") if (parts.length < 2) { - res.sendError(HttpServletResponse.SC_BAD_REQUEST, - s"Unexpected path info in request (URI = ${req.getRequestURI()}") - return + res.sendRedirect("/") } val appId = parts(1) diff --git a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala index 8737cd5bb3241..db02cf85693a2 100644 --- a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala +++ b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala @@ -644,6 +644,19 @@ class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with Matchers val actualContentType = conn.getContentType assert(actualContentType === expectedContentType) } + + test("Redirect to the root page when accessed to /history/") { + val port = server.boundPort + val url = new URL(s"http://localhost:$port/history/") + val conn = url.openConnection().asInstanceOf[HttpURLConnection] + conn.setRequestMethod("GET") + conn.setUseCaches(false) + conn.setDefaultUseCaches(false) + conn.setInstanceFollowRedirects(false) + conn.connect() + assert(conn.getResponseCode === 302) + assert(conn.getHeaderField("Location") === s"http://localhost:$port/") + } } object HistoryServerSuite {