Skip to content

Commit da71e30

Browse files
sarutakdongjoon-hyun
authored andcommitted
[SPARK-31697][WEBUI] HistoryServer should set Content-Type
### What changes were proposed in this pull request? This PR changes HistoryServer to set Content-Type. I noticed that we will get html as plain text when we access to wrong URLs which represent non-existence appId on HistoryServer. ``` <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="/static/bootstrap.min.css" type="text/css"/><link rel="stylesheet" href="/static/vis-timeline-graph2d.min.css" type="text/css"/><link rel="stylesheet" href="/static/webui.css" type="text/css"/><link rel="stylesheet" href="/static/timeline-view.css" type="text/css"/><script src="/static/sorttable.js"></script><script src="/static/jquery-3.4.1.min.js"></script><script src="/static/vis-timeline-graph2d.min.js"></script><script src="/static/bootstrap.bundle.min.js"></script><script src="/static/initialize-tooltips.js"></script><script src="/static/table.js"></script><script src="/static/timeline-view.js"></script><script src="/static/log-view.js"></script><script src="/static/webui.js"></script><script>setUIRoot('')</script> <link rel="shortcut icon" href="/static/spark-logo-77x50px-hd.png"></link> <title>Not Found</title> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-12"> <h3 style="vertical-align: middle; display: inline-block;"> <a style="text-decoration: none" href="/"> <img src="/static/spark-logo-77x50px-hd.png"/> <span class="version" style="margin-right: 15px;">3.1.0-SNAPSHOT</span> </a> Not Found </h3> </div> </div> <div class="row"> <div class="col-12"> <div class="row">Application local-1589239 not found.</div> </div> </div> </div> </body> </html> ``` The reason is Content-Type not set. I confirmed it with `curl -I http://localhost:18080/history/<wrong-appId>` ``` HTTP/1.1 404 Not Found Date: Wed, 13 May 2020 06:59:29 GMT Cache-Control: no-cache, no-store, must-revalidate X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Content-Length: 1778 Server: Jetty(9.4.18.v20190429) ``` ### Why are the changes needed? This is a bug. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? I added a test case for this issue. Closes apache#28519 from sarutak/fix-content-type. Authored-by: Kousuke Saruta <sarutak@oss.nttdata.com> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org> (cherry picked from commit 7952f44) Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent ce52f61 commit da71e30

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class HistoryServer(
6969

7070
private val loaderServlet = new HttpServlet {
7171
protected override def doGet(req: HttpServletRequest, res: HttpServletResponse): Unit = {
72+
73+
res.setContentType("text/html;charset=utf-8")
74+
7275
// Parse the URI created by getAttemptURI(). It contains an app ID and an optional
7376
// attempt ID (separated by a slash).
7477
val parts = Option(req.getPathInfo()).getOrElse("").split("/")

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,17 @@ class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with Matchers
693693
out.close()
694694
}
695695

696+
test("SPARK-31697: HistoryServer should set Content-Type") {
697+
val port = server.boundPort
698+
val nonExistenceAppId = "local-non-existence"
699+
val url = new URL(s"http://localhost:$port/history/$nonExistenceAppId")
700+
val conn = url.openConnection().asInstanceOf[HttpURLConnection]
701+
conn.setRequestMethod("GET")
702+
conn.connect()
703+
val expectedContentType = "text/html;charset=utf-8"
704+
val actualContentType = conn.getContentType
705+
assert(actualContentType === expectedContentType)
706+
}
696707
}
697708

698709
object HistoryServerSuite {

0 commit comments

Comments
 (0)