本文整理汇总了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
)
示例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)
示例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)
示例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
)