本文整理汇总了Scala中play.filters.gzip.GzipFilter类的典型用法代码示例。如果您正苦于以下问题:Scala GzipFilter类的具体用法?Scala GzipFilter怎么用?Scala GzipFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GzipFilter类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: injectorModules
//设置package包名称以及导入依赖的类
package global
import actors.ChadashSystem
import com.google.inject.{Guice, Module}
import play.api.mvc.{EssentialAction, Filters}
import play.api.{Application, GlobalSettings, Logger, Mode}
import play.filters.gzip.GzipFilter
import play.filters.headers.SecurityHeadersFilter
trait AppGlobalSettings extends GlobalSettings {
private var INJECTOR: Option[com.google.inject.Injector] = None
def injectorModules(): Seq[Module]
override def onStart(app: Application) {
INJECTOR = Some(Guice.createInjector(injectorModules(): _*))
}
override def onStop(app: Application) {
Logger.info("Application shutdown...")
if(app.mode != Mode.Test)
ChadashSystem.system.shutdown()
}
override def doFilter(next: EssentialAction): EssentialAction = {
Filters(super.doFilter(next), new GzipFilter(), SecurityHeadersFilter())
}
override def getControllerInstance[A](controllerClass: Class[A]): A = {
INJECTOR match {
case Some(x) => x.getInstance(controllerClass)
case None => throw new UnsupportedOperationException("The DI framework has not been setup yet!")
}
}
}
示例2: DefaultFilter
//设置package包名称以及导入依赖的类
package filters
import javax.inject._
import play.api.Configuration
import play.api.http.HttpFilters
import play.filters.gzip.GzipFilter
@Singleton
class DefaultFilter @Inject()(gzipFilter: GzipFilter, configuration: Configuration) extends HttpFilters {
def filters = {
if (configuration.getString("spirit.mode").getOrElse("dev").equals("dev")) {
Seq(gzipFilter)
} else {
Seq.empty
}
}
}
示例3: AppLoader
//设置package包名称以及导入依赖的类
import models.{AuthorizeStoreCache, PendingContentStoreCache}
import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.api._
import play.filters.gzip.GzipFilter
import router.Routes
class AppLoader extends ApplicationLoader {
override def load(context: Context): Application = {
LoggerConfigurator(context.environment.classLoader)
.foreach(_.configure(context.environment))
new AppComponents(context).application
}
}
class AppComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with EhCacheComponents {
implicit val executionContext =
play.api.libs.concurrent.Execution.Implicits.defaultContext
implicit lazy val authorizeStoreCache = AuthorizeStoreCache(
cacheApi("authorizeStore"))
implicit lazy val pendingConsentStoreCache = PendingContentStoreCache(
cacheApi("pendingConsentStore"))
implicit val config = configuration.underlying
lazy val applicationController = new controllers.Application
lazy val assets = new controllers.Assets(httpErrorHandler)
// Routes is a generated class
override def router: Router =
new Routes(httpErrorHandler, applicationController, assets)
val gzipFilter = new GzipFilter(shouldGzip = (request, response) => {
val contentType = response.header.headers.get("Content-Type")
contentType.exists(_.startsWith("text/html")) ||
request.path.endsWith("jsroutes.js")
})
override lazy val httpFilters: Seq[EssentialFilter] = Seq(gzipFilter)
}
示例4: Filters
//设置package包名称以及导入依赖的类
import javax.inject._
import play.api._
import play.api.http.HttpFilters
import play.api.http.HttpFilters
import play.filters.gzip.GzipFilter
import play.filters.cors.CORSFilter
import play.api.mvc._
import filters.LoggingFilter
@Singleton
class Filters @Inject() (
env: Environment,
gzip: GzipFilter,
log: LoggingFilter,
cors: CORSFilter) extends HttpFilters {
override val filters = {
// Use the example filter if we're running development mode. If
// we're running in production or test mode then don't use any
// filters at all.
if (env.mode == Mode.Dev) Seq(gzip, log, cors) else Seq.empty
}
}
示例5: LoggingFilter
//设置package包名称以及导入依赖的类
import java.nio.charset.Charset
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import scala.concurrent.Future
import scala.util._
import play.api._
import play.api.http._
import play.api.http.DefaultHttpFilters
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc._
import play.filters.gzip.GzipFilter
import akka.stream.Materializer
import com.google.common.base.Stopwatch
class LoggingFilter(val mat: Materializer) extends Filter {
val logger = Logger(this.getClass)
def apply(next: (RequestHeader) => Future[Result])(request: RequestHeader): Future[Result] = {
val stopwatch = Stopwatch.createStarted();
def logginMessage(): String =
s"method=${request.method} uri=${request.uri} remote-address=${request.remoteAddress} took=${stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)}ms"
next(request).andThen {
case Success(result) if result.header.status >= 500 =>
getBody(result).foreach { body =>
logger.error(s"${logginMessage()} returned=${result.header.status} body=$body")
}
case Success(result) =>
logger.trace(s"${logginMessage()} returned=${result.header.status}")
case Failure(ex) =>
logger.error(logginMessage(), ex)
}
}
def getBody(result: Result): Future[String] = result.body match {
case HttpEntity.Strict(data, _) =>
Future.successful(data.decodeString(Charset.defaultCharset()))
case entity: HttpEntity.Streamed =>
entity.consumeData(mat).map { data =>
data.decodeString(Charset.defaultCharset())
}
case other =>
Future.successful(s"Cannot read body of $other")
}
}
class Filters @Inject() (
gzip: GzipFilter,
logging: LoggingFilter) extends DefaultHttpFilters(gzip, logging)
示例6: Filters
//设置package包名称以及导入依赖的类
import javax.inject._
import akka.stream.Materializer
import play.api.http.HttpFilters
import play.filters.gzip.GzipFilter
@Singleton
class Filters @Inject() (implicit val mat: Materializer) extends HttpFilters {
override val filters =
Seq(
new GzipFilter(shouldGzip = (request, response) => {
val contentType = response.header.headers.find(t => t._1.trim.toLowerCase == "content-type").map(_._2).getOrElse("").toLowerCase
contentType.contains("text") || contentType.contains("json") || contentType.contains("javascript")
}
)
)
}
示例7: Filters
//设置package包名称以及导入依赖的类
import javax.inject._
import akka.stream.Materializer
import filters.{BasicAuthenticationFilter, BasicAuthenticationFilterConfiguration, LoggingFilter}
import play.api._
import play.api.http.HttpFilters
import play.filters.gzip.GzipFilter
@Singleton
class Filters @Inject()(env: Environment, configuration: Configuration, loggingFilter: LoggingFilter)
(implicit val materializer: Materializer) extends HttpFilters {
override val filters = {
Seq(
loggingFilter,
new BasicAuthenticationFilter(BasicAuthenticationFilterConfiguration parse configuration, materializer),
new GzipFilter(shouldGzip = (request, response) =>
response.body.contentType.exists(_.startsWith("text/html")) || request.path.endsWith("jsroutes.js"))
)
}
}
示例8: Filters
//设置package包名称以及导入依赖的类
import javax.inject._
import play.api._
import play.api.http.HttpFilters
import play.filters.gzip.GzipFilter
import filters.{ControlOriginFilter, ExampleFilter}
@Singleton
class Filters @Inject() (
env: Environment,
exampleFilter: ExampleFilter,
gzipFilter: GzipFilter,
controlOriginFilter: ControlOriginFilter) extends HttpFilters {
override val filters = {
// Use the example filter if we're running development mode. If
// we're running in production or test mode then don't use any
// filters at all.
//if (env.mode == Mode.Dev) Seq(exampleFilter, controlOriginFilter, gzipFilter) else Seq.empty
Seq(exampleFilter, controlOriginFilter, gzipFilter)
}
}
示例9: XResponseTimeHeader
//设置package包名称以及导入依赖的类
package filters
import javax.inject.Inject
import akka.stream.Materializer
import controllers.BuildInfo
import play.api.http.DefaultHttpFilters
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.{ Filter, RequestHeader, Result }
import play.filters.gzip.GzipFilter
import scala.concurrent.Future
class XResponseTimeHeader @Inject() (implicit val mat: Materializer) extends Filter {
def apply(nextFilter: RequestHeader => Future[Result])(requestHeader: RequestHeader): Future[Result] = {
val startTime = System.currentTimeMillis
nextFilter(requestHeader).map { result =>
val endTime = System.currentTimeMillis
val responseTime = endTime - startTime
val env = sys.props.get("environment").getOrElse("default")
if (env == "local") {
result.withHeaders(
"X-Response-Time" -> responseTime.toString,
"Server" -> (BuildInfo.name + "/" + BuildInfo.version),
"Access-Control-Allow-Origin" -> "*",
"Access-Control-Allow-Methods" -> "OPTIONS, GET, POST, PUT, DELETE, HEAD",
"Access-Control-Allow-Headers" -> "Accept, Content-Type, Origin, X-Json, X-Prototype-Version, X-Requested-With",
"Access-Control-Allow-Credentials" -> "true"
)
} else {
result.withHeaders(
"X-Response-Time" -> responseTime.toString,
"Server" -> (BuildInfo.name + "/" + BuildInfo.version)
)
}
}
}
}
class Filters @Inject() (gzipFilter: GzipFilter, responseTimeHeader: XResponseTimeHeader)
extends DefaultHttpFilters(gzipFilter, responseTimeHeader)
示例10: Filters
//设置package包名称以及导入依赖的类
import javax.inject._
import akka.stream.Materializer
import filters.GoogleFilter
import play.api.http.HttpFilters
import play.api.mvc.EssentialAction
import play.filters.gzip.GzipFilter
@Singleton
class Filters @Inject() (googleFilter: GoogleFilter, implicit val mat: Materializer) extends HttpFilters {
val next: EssentialAction = null
val ret = googleFilter(next)
override val filters =
Seq(
new GzipFilter(shouldGzip = (request, response) => {
val contentType = response.body.contentType.getOrElse("").toLowerCase
contentType.contains("text") || contentType.contains("json") || contentType.contains("javascript")
}
),
googleFilter
)
}