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


Scala CORSFilter类代码示例

本文整理汇总了Scala中play.filters.cors.CORSFilter的典型用法代码示例。如果您正苦于以下问题:Scala CORSFilter类的具体用法?Scala CORSFilter怎么用?Scala CORSFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CORSFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: CustomCORSFilter

//设置package包名称以及导入依赖的类
package filters

import javax.inject.{Inject, Singleton}

import akka.stream.Materializer
import play.api.http.HeaderNames
import play.api.mvc.{Filter, RequestHeader, Result}
import play.filters.cors.CORSFilter

import scala.concurrent.{ExecutionContext, Future}


@Singleton
class CustomCORSFilter @Inject()(corsFilter: CORSFilter)
                                (implicit override val mat: Materializer,
                                 exec: ExecutionContext) extends Filter {

  override def apply(nextFilter: RequestHeader => Future[Result])
                    (requestHeader: RequestHeader): Future[Result] = {
    requestHeader.headers.get(HeaderNames.ORIGIN) match {
      case (Some("null")) =>
        val newHeaders = requestHeader.headers
          .remove(HeaderNames.ORIGIN)
          .add(HeaderNames.ORIGIN -> "http://file.url.local.null")
        val mappedOrigin = requestHeader.copy(headers = newHeaders)
        corsFilter(nextFilter)(mappedOrigin)
          .map { result =>
            result.withHeaders(HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN -> "null")
          }
      case _ => corsFilter(nextFilter)(requestHeader)
    }
  }
} 
开发者ID:umbc-cmcs447-grp,项目名称:rest-api,代码行数:34,代码来源:CustomCORSFilter.scala

示例2: 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

示例3: GriffinApiLoader

//设置package包名称以及导入依赖的类
import com.softwaremill.macwire._
import controllers.Assets
import filters.LoggingFilter
import play.api.ApplicationLoader.Context
import play.api._
import play.api.i18n._
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.filters.cors.{CORSConfig, CORSFilter}
import router.Routes
import services.ServicesModule



class GriffinApiLoader extends ApplicationLoader {
  def load(context: Context): Application = new GriffinComponents(context).application
}


class GriffinComponents(context: Context)
  extends BuiltInComponentsFromContext(context)
    with ServicesModule
    with I18nComponents
    with AhcWSComponents
{
  // set up logger
  LoggerConfigurator(context.environment.classLoader).foreach {
    _.configure(context.environment)
  }

  lazy val assets: Assets = wire[Assets]
  lazy val router: Router = {
    // add the prefix string in local scope for the Routes constructor
    val prefix: String = "/"
    wire[Routes]
  }

  lazy val corsFilter = CORSFilter(CORSConfig.fromConfiguration(configuration))

  lazy val loggingFilter = new LoggingFilter
  lazy val filters = wire[Filters]

  override lazy val httpFilters: Seq[EssentialFilter] =
    Seq(loggingFilter,corsFilter)

} 
开发者ID:yarshad,项目名称:griffin-api,代码行数:48,代码来源:GriffinApiLoader.scala

示例4: Filters

//设置package包名称以及导入依赖的类
import javax.inject._
import play.api._
import play.api.http.HttpFilters
import play.api.mvc._

import filters.ExampleFilter

import play.filters.cors.CORSFilter

@Singleton
class Filters @Inject() (
  env: Environment,
  exampleFilter: ExampleFilter,
  corsFilter: 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.
    val seq = Seq(corsFilter)
    if (env.mode == Mode.Dev) seq ++ Seq(exampleFilter)
    else seq
  }

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

示例5: RegExCORSFilter

//设置package包名称以及导入依赖的类
package com.github.dgilling.regexcors

import akka.stream.Materializer
import play.api.Logger
import play.api.http.{DefaultHttpErrorHandler, HttpErrorHandler}
import play.api.mvc.{Result, RequestHeader, Filter}
import play.core.j.JavaHttpErrorHandlerAdapter
import play.filters.cors.{CORSFilter, AbstractCORSPolicy, CORSConfig}

import scala.concurrent.Future


class RegExCORSFilter(
                  override protected val corsConfig: CORSConfig = CORSConfig(),
                  override protected val errorHandler: HttpErrorHandler = DefaultHttpErrorHandler,
                  private val pathPrefixes: Seq[String] = Seq("/"),
                  private val ignoredPathPrefixes: Seq[String] = Seq.empty[String])(override implicit val mat: Materializer)
  extends CORSFilter {

  // Java constructor
  def this(corsConfig: CORSConfig, errorHandler: play.http.HttpErrorHandler, pathPrefixes: java.util.List[String])(mat: Materializer) = {
    this(corsConfig, new JavaHttpErrorHandlerAdapter(errorHandler), Seq(pathPrefixes.toArray.asInstanceOf[Array[String]]: _*))(mat)
  }

  override protected val logger = Logger(classOf[CORSFilter])

  override def apply(f: RequestHeader => Future[Result])(request: RequestHeader): Future[Result] = {
    if (pathPrefixes.exists(request.path.startsWith) &&
      !ignoredPathPrefixes.exists(request.path.startsWith)) {
      filterRequest(f, request)
    } else {
      f(request)
    }
  }
}

object RegExCORSFilter {

  val RequestTag = "CORS_REQUEST"

  def apply(corsConfig: CORSConfig = CORSConfig(), errorHandler: HttpErrorHandler = DefaultHttpErrorHandler,
            pathPrefixes: Seq[String] = Seq("/"))(implicit mat: Materializer) =
    new CORSFilter(corsConfig, errorHandler, pathPrefixes)

} 
开发者ID:dgilling,项目名称:play-regex-cors,代码行数:46,代码来源:RegExCORSFilter.scala

示例6: Filters

//设置package包名称以及导入依赖的类
import javax.inject._
import play.api._
import play.api.http.HttpFilters
import play.filters.cors.CORSFilter
import play.api.mvc._



@Singleton
class Filters @Inject() (
  env: Environment,
  corsFilter: 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(corsFilter) else Seq.empty
  }

} 
开发者ID:aholland,项目名称:play-scalajs-workbench-example,代码行数:22,代码来源:Filters.scala

示例7: Filters

//设置package包名称以及导入依赖的类
import javax.inject._
import play.api._
import play.api.http.HttpFilters
import play.filters.cors.CORSFilter


@Singleton
class Filters @Inject() (
  env: Environment,  
  corsFilter: 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(corsFilter) else Seq(corsFilter)
  }

} 
开发者ID:malaman,项目名称:scala-weather-app,代码行数:21,代码来源:Filters.scala

示例8: 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

示例9: 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

示例10: Filters

//设置package包名称以及导入依赖的类
import javax.inject._

import play.api._
import play.api.http.HttpFilters
import play.api.mvc._
import filters.ExampleFilter
import play.filters.cors.CORSFilter


@Singleton
class Filters @Inject() (
  env: Environment,
  exampleFilter: ExampleFilter,
  corsFilter: 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(exampleFilter) else Seq(corsFilter)
    Seq.empty
  }

} 
开发者ID:hackstreetb0ys,项目名称:twitter-sentiment-api,代码行数:25,代码来源:Filters.scala

示例11: CorsWithLoggingFilter

//设置package包名称以及导入依赖的类
package filters

import javax.inject.Inject
import akka.stream.Materializer
import play.api.http.HttpFilters
import play.api.Logger
import play.api.mvc._
import play.filters.cors.CORSFilter
import scala.concurrent.{ExecutionContext, Future}


class CorsWithLoggingFilter @javax.inject.Inject() (corsFilter: CORSFilter, loggingFilter: LoggingFilter) extends HttpFilters {
  def filters = Seq(corsFilter, loggingFilter)
}

class LoggingFilter @Inject() (implicit val mat: Materializer, ec: ExecutionContext) extends Filter {

  def apply(nextFilter: RequestHeader => Future[Result])
           (requestHeader: RequestHeader): Future[Result] = {

    val startTime = System.currentTimeMillis
    val headerMap = requestHeader.headers.toMap

    nextFilter(requestHeader).map { result =>
      val endTime = System.currentTimeMillis
      val requestTime = endTime - startTime

      val line = Seq(
        requestHeader.method,
        s"${requestHeader.host}${requestHeader.uri}",
        result.header.status,
        s"${requestTime}ms",
        headerMap.getOrElse("User-Agent", Nil).mkString(","),
        headerMap.getOrElse("X-Forwarded-For", Nil).mkString(","),
        headerMap.getOrElse(
          "CF-Connecting-IP",
          headerMap.getOrElse("True-Client-IP", Nil)
        ).mkString(",")
      ).mkString(" ")

      Logger.info(line)

      result.withHeaders("Request-Time" -> requestTime.toString)
    }
  }
} 
开发者ID:flowvault,项目名称:proxy,代码行数:47,代码来源:Filters.scala

示例12: ServerModule

//设置package包名称以及导入依赖的类
package uk.co.telegraph.utils.server

import akka.actor.ActorSystem
import com.google.inject.{AbstractModule, Provides}
import com.google.inject.Key.get
import com.google.inject.multibindings.Multibinder.newSetBinder
import play.api.mvc.EssentialFilter
import play.filters.cors.CORSFilter
import uk.co.telegraph.utils.server.filters.{AuthFilter, EventIdFilter}
import java.util.{Set => JSet}

import scala.language.postfixOps
import scala.collection.convert.WrapAsScala._
import uk.co.telegraph.utils.client.GenericClient
import uk.co.telegraph.utils.client.monitor.Monitor

class ServerModule extends AbstractModule {
  override def configure(): Unit = {
    val filterBinder = newSetBinder(binder(), get(classOf[EssentialFilter]))
    filterBinder.addBinding().to(classOf[CORSFilter])
    filterBinder.addBinding().to(classOf[EventIdFilter])
    filterBinder.addBinding().to(classOf[AuthFilter])
  }

  @Provides
  def monitorProvider(clientsSet:JSet[GenericClient])(implicit system:ActorSystem): Monitor = {
    Monitor(clientsSet.toSeq)
  }
} 
开发者ID:telegraph,项目名称:tmg-utils,代码行数:30,代码来源:ServerModule.scala

示例13: Filters

//设置package包名称以及导入依赖的类
import com.google.inject.{Inject, Singleton}
import play.api._
import play.api.http.HttpFilters
import play.filters.cors.CORSFilter
@Singleton
class Filters @Inject()(
                        env: Environment,
                        corsFilter: 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(corsFilter) else Seq.empty
 }
} 
开发者ID:aholland,项目名称:autowire-circe,代码行数:16,代码来源:Filters.scala

示例14: Filters

//设置package包名称以及导入依赖的类
import javax.inject._

import play.api._
import play.api.http.{ DefaultHttpFilters, HttpFilters }
import filters.ExampleFilter
import play.filters.cors.CORSFilter


@Singleton
class Filters @Inject() (
    env: Environment,
    exampleFilter: ExampleFilter,
    corsFilter: 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(exampleFilter, corsFilter) else Seq(corsFilter)
  }

} 
开发者ID:FScoward,项目名称:billets-en-concert,代码行数:24,代码来源:Filters.scala

示例15: Filters

//设置package包名称以及导入依赖的类
import javax.inject._
import play.api._
import play.api.http.HttpFilters
import play.api.mvc._
import play.filters.cors.CORSFilter


@Singleton
class Filters @Inject() (
  env: Environment,
  corsFilter: 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(corsFilter) else Seq.empty
  }

} 
开发者ID:jjinking,项目名称:chp,代码行数:21,代码来源:Filters.scala


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