Skip to content

Commit bd4750c

Browse files
gyogalArnavBalyan
authored andcommitted
[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.
1 parent 00c92d2 commit bd4750c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

server/src/main/scala/org/apache/livy/server/LivyServer.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import scala.concurrent.Future
3030
import org.apache.hadoop.security.{SecurityUtil, UserGroupInformation}
3131
import org.apache.hadoop.security.authentication.server._
3232
import org.eclipse.jetty.servlet.FilterHolder
33-
import org.scalatra.{NotFound, ScalatraServlet}
33+
import org.scalatra.{ApiFormats, NotFound, ScalatraServlet}
3434
import org.scalatra.metrics.MetricsBootstrap
3535
import org.scalatra.metrics.MetricsSupportExtensions._
3636
import org.scalatra.servlet.{MultipartConfig, ServletApiImplicits}
@@ -179,14 +179,26 @@ class LivyServer extends Logging {
179179
// Servlet for hosting static files such as html, css, and js
180180
// Necessary since Jetty cannot set it's resource base inside a jar
181181
// Returns 404 if the file does not exist
182-
val staticResourceServlet = new ScalatraServlet {
182+
val staticResourceServlet = new ScalatraServlet with ApiFormats {
183+
184+
addMimeMapping("image/png", "png")
185+
addMimeMapping("application/vnd.ms-fontobject", "eot")
186+
addMimeMapping("image/svg+xml", "svg")
187+
addMimeMapping("font/ttf", "ttf")
188+
addMimeMapping("font/woff", "woff")
189+
addMimeMapping("font/woff2", "woff2")
190+
183191
get("/*") {
184192
val fileName = params("splat")
185193
val notFoundMsg = "File not found"
186194

187195
if (!fileName.isEmpty) {
188196
getClass.getResourceAsStream(s"ui/static/$fileName") match {
189-
case is: InputStream => new BufferedInputStream(is)
197+
case is: InputStream => {
198+
val extension = fileName.split("\\.").last
199+
contentType = formats(extension)
200+
new BufferedInputStream(is)
201+
}
190202
case null => NotFound(notFoundMsg)
191203
}
192204
} else {

0 commit comments

Comments
 (0)