当前位置: 首页>>代码示例>>Scala>>正文


Scala GzipFilter类代码示例

本文整理汇总了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!")
    }
  }
} 
开发者ID:lifeway,项目名称:Chadash,代码行数:37,代码来源:AppGlobalSettings.scala

示例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
    }
  }

} 
开发者ID:P1tt187,项目名称:spirit-play,代码行数:21,代码来源:DefaultFilter.scala

示例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)
} 
开发者ID:zalando-incubator,项目名称:OAuth2-mock-play,代码行数:45,代码来源:AppLoader.scala

示例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
  }

} 
开发者ID:trumanw,项目名称:cloud-oauth-play,代码行数:27,代码来源:Filters.scala

示例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) 
开发者ID:fravega,项目名称:scala-play-seed.g8,代码行数:60,代码来源:Filters.scala

示例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")
        }
      )
    )

} 
开发者ID:joymufeng,项目名称:play-scholar,代码行数:19,代码来源:Filters.scala

示例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"))
    )

  }

} 
开发者ID:lavenderx,项目名称:play2.5-examples,代码行数:26,代码来源:Filters.scala

示例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)
  }

} 
开发者ID:teruuuuuu,项目名称:todo_server_scala,代码行数:26,代码来源:Filters.scala

示例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) 
开发者ID:ONSdigital,项目名称:sbr-pipeline-test,代码行数:44,代码来源:Filters.scala

示例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
    )

} 
开发者ID:joymufeng,项目名称:play-google,代码行数:25,代码来源:Filters.scala


注:本文中的play.filters.gzip.GzipFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。