@@ -27,6 +27,7 @@ import scala.xml.Node
2727import org .eclipse .jetty .server .Server
2828import org .eclipse .jetty .server .handler ._
2929import org .eclipse .jetty .servlet ._
30+ import org .eclipse .jetty .servlets .GzipFilter
3031import org .eclipse .jetty .util .thread .QueuedThreadPool
3132import org .json4s .JValue
3233import org .json4s .jackson .JsonMethods .{pretty , render }
@@ -166,8 +167,26 @@ private[spark] object JettyUtils extends Logging {
166167 contextHandler
167168 }
168169
170+ private def addDefaultFilters (handlers : Seq [ServletContextHandler ], conf : SparkConf ): Unit = {
171+ val compression = conf.getBoolean(" spark.ui.compression" , true )
172+ if (compression) {
173+ // Enable gzip for Web UI
174+ logInfo(" Adding filter: GzipFilter" )
175+ val holder = new FilterHolder ()
176+ holder.setClassName(classOf [GzipFilter ].getName())
177+ holder.setInitParameter(" methods" , " GET,POST" )
178+ holder.setInitParameter(" mimeTypes" , " text/html,text/xml,text/plain,text/css," +
179+ " text/javascript,text/json,application/x-javascript,application/javascript," +
180+ " application/json,application/xml,application/xml+xhtml,image/svg+xml" )
181+ val enumDispatcher = java.util.EnumSet .of(DispatcherType .ASYNC , DispatcherType .ERROR ,
182+ DispatcherType .FORWARD , DispatcherType .INCLUDE , DispatcherType .REQUEST )
183+ handlers.foreach { case (handler) => handler.addFilter(holder, " /*" , enumDispatcher) }
184+ }
185+ }
186+
169187 /** Add filters, if any, to the given list of ServletContextHandlers */
170188 def addFilters (handlers : Seq [ServletContextHandler ], conf : SparkConf ) {
189+ addDefaultFilters(handlers, conf)
171190 val filters : Array [String ] = conf.get(" spark.ui.filters" , " " ).split(',' ).map(_.trim())
172191 filters.foreach {
173192 case filter : String =>
0 commit comments