本文整理汇总了Scala中play.api.http.DefaultHttpFilters类的典型用法代码示例。如果您正苦于以下问题:Scala DefaultHttpFilters类的具体用法?Scala DefaultHttpFilters怎么用?Scala DefaultHttpFilters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultHttpFilters类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Filters
//设置package包名称以及导入依赖的类
import javax.inject.Inject
import play.api.http.DefaultHttpFilters
import play.filters.cors.CORSFilter
import play.filters.csrf.CSRFFilter
import play.filters.headers.SecurityHeadersFilter
import play.filters.hosts.AllowedHostsFilter
class Filters @Inject() (
csrfFilter: CSRFFilter,
allowedHostsFilter: AllowedHostsFilter,
securityHeadersFilter: SecurityHeadersFilter,
corsFilter: CORSFilter
) extends DefaultHttpFilters(
csrfFilter,
allowedHostsFilter,
securityHeadersFilter,
corsFilter
)
开发者ID:SkySchulz,项目名称:url-score,代码行数:21,代码来源:Filters.scala
示例2: LoggingFilter
//设置package包名称以及导入依赖的类
package filters
import javax.inject.Inject
import akka.stream.Materializer
import play.api.Logger
import play.api.http.DefaultHttpFilters
import play.api.mvc.{Filter, RequestHeader, Result}
import play.filters.cors.CORSFilter
import scala.concurrent.{ExecutionContext, Future}
class LoggingFilter @Inject() (implicit val mat: Materializer, ec: ExecutionContext) extends Filter {
val X_REQUEST_ID = "X-Request-Id"
val X_RESPONSE_TIME = "X-Response-Time"
val accessLog = Logger("access")
def apply(nextFilter: RequestHeader => Future[Result])
(requestHeader: RequestHeader): Future[Result] = {
val startTime = System.currentTimeMillis
val requestId = requestHeader.headers.get(X_REQUEST_ID)
val linepre = s"req-${requestHeader.id}: ${requestHeader.method} ${requestHeader.uri}" +
requestId.map(" (" + X_REQUEST_ID + ": " + _ + ")").getOrElse("")
accessLog.info(linepre)
nextFilter(requestHeader).map { result =>
val endTime = System.currentTimeMillis
val requestTime = endTime - startTime
accessLog.info(s"${linepre} returned ${result.header.status} in ${requestTime}ms ")
val responseHeaders = Seq(
X_RESPONSE_TIME -> requestTime.toString
) ++ requestId.map(X_REQUEST_ID -> _)
result.withHeaders(responseHeaders:_*)
}
}
}
class Filters @Inject() (corsFilter: CORSFilter, loggingFilter: LoggingFilter)
extends DefaultHttpFilters(corsFilter,loggingFilter)
开发者ID:GalacticFog,项目名称:gestalt-security,代码行数:46,代码来源:Filters.scala
示例3: TLSFilters
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import akka.stream.Materializer
import play.api.Environment
import play.api.http.DefaultHttpFilters
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
class TLSFilters @Inject() (
implicit val mat: Materializer,
ec: ExecutionContext, env: Environment) extends Filter {
def apply(nextFilter: RequestHeader => Future[Result])(requestHeader: RequestHeader): Future[Result] = {
if(requestHeader.headers.get("x-forwarded-proto").getOrElse("http") != "https" && env.mode == play.api.Mode.Prod)
Future.successful(Results.MovedPermanently("https://" + requestHeader.host + requestHeader.uri))
else
nextFilter(requestHeader).map { _.withHeaders("Strict-Transport-Security" -> "max-age=31536000") }
}
}
class Filters @Inject() (tls: TLSFilters) extends DefaultHttpFilters(tls)
开发者ID:tictactoki,项目名称:Immutaskable,代码行数:26,代码来源:Filters.scala
示例4: Filters
//设置package包名称以及导入依赖的类
import javax.inject.Inject
import play.api.http.DefaultHttpFilters
import play.filters.csrf.CSRFFilter
import play.filters.headers.SecurityHeadersFilter
import play.filters.hosts.AllowedHostsFilter
import org.zalando.hutmann.filters.CreateFlowIdFilter
class Filters @Inject() (
csrfFilter: CSRFFilter,
allowedHostsFilter: AllowedHostsFilter,
securityHeadersFilter: SecurityHeadersFilter,
flowIdFilter: CreateFlowIdFilter
) extends DefaultHttpFilters(
csrfFilter,
allowedHostsFilter,
securityHeadersFilter,
flowIdFilter
)
开发者ID:faolivera,项目名称:hutmann-performance-test,代码行数:22,代码来源:Filters.scala
注:本文中的play.api.http.DefaultHttpFilters类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论