This is an automated email from the ASF dual-hosted git repository. ggal pushed a commit to branch branch-0.9 in repository https://gitbox.apache.org/repos/asf/incubator-livy.git
commit 7e838066add7871251cbeea113884c22b35d33ce Author: György Gál <[email protected]> AuthorDate: Sat Dec 6 22:53:01 2025 -0500 [LIVY-1026] Fix Content-Types for nosniff header ## What changes were proposed in this pull request? In LIVY-785 the `X-Content-Type-Options: nosniff` HTTP header was added, however this breaks transferring some files where the Content-Type is not correctly specified. ## How was this patch tested? Tested by running the server locally. --- .../main/scala/org/apache/livy/server/LivyServer.scala | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/server/src/main/scala/org/apache/livy/server/LivyServer.scala b/server/src/main/scala/org/apache/livy/server/LivyServer.scala index 049dae04..7b6f323e 100644 --- a/server/src/main/scala/org/apache/livy/server/LivyServer.scala +++ b/server/src/main/scala/org/apache/livy/server/LivyServer.scala @@ -30,7 +30,7 @@ import scala.concurrent.Future import org.apache.hadoop.security.{SecurityUtil, UserGroupInformation} import org.apache.hadoop.security.authentication.server._ import org.eclipse.jetty.servlet.FilterHolder -import org.scalatra.{NotFound, ScalatraServlet} +import org.scalatra.{ApiFormats, NotFound, ScalatraServlet} import org.scalatra.metrics.MetricsBootstrap import org.scalatra.metrics.MetricsSupportExtensions._ import org.scalatra.servlet.{MultipartConfig, ServletApiImplicits} @@ -179,14 +179,26 @@ class LivyServer extends Logging { // Servlet for hosting static files such as html, css, and js // Necessary since Jetty cannot set it's resource base inside a jar // Returns 404 if the file does not exist - val staticResourceServlet = new ScalatraServlet { + val staticResourceServlet = new ScalatraServlet with ApiFormats { + + addMimeMapping("image/png", "png") + addMimeMapping("application/vnd.ms-fontobject", "eot") + addMimeMapping("image/svg+xml", "svg") + addMimeMapping("font/ttf", "ttf") + addMimeMapping("font/woff", "woff") + addMimeMapping("font/woff2", "woff2") + get("/*") { val fileName = params("splat") val notFoundMsg = "File not found" if (!fileName.isEmpty) { getClass.getResourceAsStream(s"ui/static/$fileName") match { - case is: InputStream => new BufferedInputStream(is) + case is: InputStream => { + val extension = fileName.split("\\.").last + contentType = formats(extension) + new BufferedInputStream(is) + } case null => NotFound(notFoundMsg) } } else {
