• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Headers类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: AllLogExpectationBuilder

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

import play.api.mvc.Headers
import scala.concurrent.duration._

case class AllLogExpectationBuilder(
  methodOpt: Option[HttpMethod], // accept all method if None
  headers: Headers = Headers(),
  bodies: Set[ArrayByte],
  val queue: AccessLogQueue
) {
  def method: String = methodOpt.fold("")(_.value)

  
  def apply(timeout: FiniteDuration = 1.second, interval: Int = 100): Unit = {
    new AllLogExecutionContext(this).run(timeout, interval)
  }
} 
开发者ID:xuwei-k,项目名称:httpmock,代码行数:19,代码来源:AllLogExpectationBuilder.scala


示例2: Expectation

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

import play.api.mvc.Headers

final class Expectation(logs: AccessLogQueue) {
  def expect(
    methodNullable: HttpMethod = null,
    headers: Headers = Headers(),
    bodyOpt: Option[ArrayByte] = None,
    count: Int = 1
  ): EachLogExpectationBuilder = new EachLogExpectationBuilder(
    methodOpt = Option(methodNullable),
    headers = headers,
    bodyOpt = bodyOpt,
    count = count,
    logs
  )
} 
开发者ID:xuwei-k,项目名称:httpmock,代码行数:19,代码来源:Expectation.scala


示例3: EachLogExpectationBuilder

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

import java.nio.charset.Charset
import java.nio.charset.StandardCharsets.UTF_8

import akka.util.ByteString
import play.api.mvc.Headers

import scala.concurrent.duration._

final case class EachLogExpectationBuilder(
  methodOpt: Option[HttpMethod], // accept all method if None
  headers: Headers = Headers(),
  bodyOpt: Option[ArrayByte] = None, // body for sequential matcher
  count: Int = 1,
  queue: AccessLogQueue
) {
  def method: String = methodOpt.fold("")(_.value)

  def body(v: String, charset: Charset = UTF_8): EachLogExpectationBuilder =
    copy(bodyOpt = Some(ArrayByte(ByteString(v.getBytes(charset)))))

  def count(v: Int): EachLogExpectationBuilder = copy(count = v)

  def header(key: String, value: String): EachLogExpectationBuilder = copy(headers = headers.add((key, value)))

  
  def apply(timeout: FiniteDuration = 1.second, interval: Int = 100): Unit = {
    new EachLogExecutionContext(this).run(timeout, interval)
  }
} 
开发者ID:xuwei-k,项目名称:httpmock,代码行数:32,代码来源:EachLogExpectationBuilder.scala


示例4: Scopes

//设置package包名称以及导入依赖的类
package microtools.models

import play.api.mvc.Headers

case class Scopes(scopes: Set[String]) extends AnyVal {
  def contains(scope: String): Boolean = scopes.contains(scope)
}

object Scopes {
  val empty: Scopes = Scopes(Set.empty[String])

  def apply(scopes: String*): Scopes = Scopes(scopes.toSet)
}

case class ScopesByService(scopesByService: Map[String, Scopes]) extends AnyVal {
  def forService(serviceName: ServiceName): Scopes =
    scopesByService.getOrElse(serviceName.name.toLowerCase, Scopes.empty)
}

object ScopesByService {
  val scopesHeaderPrefix = "x-auth-scopes-"

  def fromHeaders(headers: Headers): ScopesByService = {
    ScopesByService(headers.headers.foldLeft(Map.empty[String, Scopes]) {
      (accu: Map[String, Scopes], header) =>
        val (key, value) = header
        if (key.toLowerCase.startsWith(scopesHeaderPrefix)) {
          val serviceName = key.drop(scopesHeaderPrefix.length).toLowerCase
          accu + (serviceName -> Scopes(accu.getOrElse(serviceName, Scopes.empty).scopes + value))
        } else
          accu
    })
  }
} 
开发者ID:21re,项目名称:play-micro-tools,代码行数:35,代码来源:Scopes.scala


示例5: ScopesSpec

//设置package包名称以及导入依赖的类
package microtools.models

import org.scalatestplus.play.PlaySpec
import play.api.mvc.Headers

class ScopesSpec extends PlaySpec {
  "Scopes" should {
    "support contains" in {
      val scopes = Scopes("R", "W")

      scopes.contains("R") mustBe true
      scopes.contains("W") mustBe true
      scopes.contains("something") mustBe false
    }

    "extract request headers" in {
      val headers = Headers(
        "X-Auth-Scopes-Customer" -> "R",
        "X-Auth-Scopes-customer" -> "W",
        "x-auth-scopes-offer"    -> "R",
        "X-AUTH-SCOPES-object"   -> "*"
      )

      val scopesByService = ScopesByService.fromHeaders(headers)

      scopesByService.forService(ServiceName("customer")) mustBe Scopes("R", "W")
      scopesByService.forService(ServiceName("offer")) mustBe Scopes("R")
      scopesByService.forService(ServiceName("object")) mustBe Scopes("*")
    }
  }
} 
开发者ID:21re,项目名称:play-micro-tools,代码行数:32,代码来源:ScopesSpec.scala


示例6: DeserializedRequestHeader

//设置package包名称以及导入依赖的类
package play.engineio

import java.net.URI

import play.api.libs.typedmap.TypedMap
import play.api.mvc.{ Headers, RequestHeader }
import play.api.mvc.request.{ RemoteConnection, RequestTarget }
import play.core.parsers.FormUrlEncodedParser


private[engineio] class DeserializedRequestHeader(
  val method:  String,
  rawUri:      String,
  val version: String,
  headerSeq:   Seq[(String, String)]
) extends RequestHeader {
  override lazy val connection = RemoteConnection("0.0.0.0", false, None)
  override def attrs = TypedMap.empty
  override lazy val headers = Headers(headerSeq: _*)
  override lazy val target = {
    new RequestTarget {
      override lazy val uri = URI.create(rawUri)
      override def uriString = rawUri
      override def path = if (uri.getPath == null) "/" else uri.getPath
      override lazy val queryMap: Map[String, Seq[String]] = if (uri.getRawQuery == null) {
        Map.empty
      } else {
        FormUrlEncodedParser.parse(uri.getRawQuery)
      }
    }
  }
} 
开发者ID:playframework,项目名称:play-socket.io,代码行数:33,代码来源:DeserializedRequestHeader.scala


示例7: ShortestPathControllerSpec

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

import scala.annotation.implicitNotFound
import scala.concurrent.Future

import play.api.http.Writeable
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.mvc.AnyContentAsEmpty
import play.api.mvc.Headers
import play.api.mvc.Result
import play.api.mvc.Results
import play.api.test.FakeRequest
import play.api.test.PlaySpecification

class ShortestPathControllerSpec extends PlaySpecification with Results {
  "End point is working#index" should {

    lazy val app = new GuiceApplicationBuilder().build
    val basicHeaders = Headers(
      "type" -> "application/json")
    def routeGET(uri: String) = getRoute(GET, uri, AnyContentAsEmpty)
    def getRoute[A](method: String, uri: String, body: A)(implicit w: Writeable[A]) = route(app, FakeRequest(method, uri, basicHeaders, body)).get

    def codeMustMatch(code: Int, result: Future[Result]) = {
      status(result) must equalTo(code)
    }

    s"End point is available" in {
      val source = "source_user"
      val destination = "destination_user"
      val result = routeGET("/shortestPath/source_user/destination_user")
      codeMustMatch(200, result)
      contentAsString(result) must contain("hops")
    }
  }
} 
开发者ID:joaoB,项目名称:shortestPath,代码行数:37,代码来源:ShortestPathControllerSpec.scala


示例8: ZipkinTraceFilter

//设置package包名称以及导入依赖的类
package jp.co.bizreach.trace.play25.filter

import javax.inject.Inject

import akka.stream.Materializer
import jp.co.bizreach.trace.ZipkinTraceServiceLike
import play.api.mvc.{Filter, Headers, RequestHeader, Result}

import scala.concurrent.Future
import scala.util.Failure


class ZipkinTraceFilter @Inject() (tracer: ZipkinTraceServiceLike)(implicit val mat: Materializer) extends Filter {

  import tracer.executionContext
  private val reqHeaderToSpanName: RequestHeader => String = ZipkinTraceFilter.ParamAwareRequestNamer

  def apply(nextFilter: (RequestHeader) => Future[Result])(req: RequestHeader): Future[Result] = {
    val serverSpan = tracer.serverReceived(
      spanName = reqHeaderToSpanName(req),
      span = tracer.newSpan(req.headers)((headers, key) => headers.get(key))
    )
    val result = nextFilter(req.copy(headers = new Headers(
      (req.headers.toMap.mapValues(_.headOption getOrElse "") ++ tracer.toMap(serverSpan)).toSeq
    )))
    result.onComplete {
      case Failure(t) => tracer.serverSend(serverSpan, "failed" -> s"Finished with exception: ${t.getMessage}")
      case _ => tracer.serverSend(serverSpan)
    }
    result
  }
}

object ZipkinTraceFilter {
  val ParamAwareRequestNamer: RequestHeader => String = { reqHeader =>
    import org.apache.commons.lang3.StringUtils
    val tags = reqHeader.tags
    val pathPattern = StringUtils.replace(tags.getOrElse(play.api.routing.Router.Tags.RoutePattern, reqHeader.path), "<[^/]+>", "")
    s"${reqHeader.method} - $pathPattern"
  }
} 
开发者ID:bizreach,项目名称:play-zipkin-tracing,代码行数:42,代码来源:ZipkinTraceFilter.scala


示例9: ZipkinTraceFilter

//设置package包名称以及导入依赖的类
package jp.co.bizreach.trace.play24.filter

import javax.inject.Inject

import jp.co.bizreach.trace.ZipkinTraceServiceLike
import play.api.mvc.{Filter, Headers, RequestHeader, Result}

import scala.concurrent.Future
import scala.util.Failure


class ZipkinTraceFilter @Inject() (tracer: ZipkinTraceServiceLike) extends Filter {

  import tracer.executionContext
  private val reqHeaderToSpanName: RequestHeader => String = ZipkinTraceFilter.ParamAwareRequestNamer

  def apply(nextFilter: (RequestHeader) => Future[Result])(req: RequestHeader): Future[Result] = {
    val serverSpan = tracer.serverReceived(
      spanName = reqHeaderToSpanName(req),
      span = tracer.newSpan(req.headers)((headers, key) => headers.get(key))
    )
    val result = nextFilter(req.copy(headers = new Headers(
      (req.headers.toMap.mapValues(_.headOption getOrElse "") ++ tracer.toMap(serverSpan)).toSeq
    )))
    result.onComplete {
      case Failure(t) => tracer.serverSend(serverSpan, "failed" -> s"Finished with exception: ${t.getMessage}")
      case _ => tracer.serverSend(serverSpan)
    }
    result
  }
}

object ZipkinTraceFilter {
  val ParamAwareRequestNamer: RequestHeader => String = { reqHeader =>
    import org.apache.commons.lang3.StringUtils
    val tags = reqHeader.tags
    val pathPattern = StringUtils.replace(tags.getOrElse(play.api.routing.Router.Tags.RoutePattern, reqHeader.path), "<[^/]+>", "")
    s"${reqHeader.method} - $pathPattern"
  }
} 
开发者ID:bizreach,项目名称:play-zipkin-tracing,代码行数:41,代码来源:ZipkinTraceFilter.scala


示例10: ZipkinTraceFilter

//设置package包名称以及导入依赖的类
package jp.co.bizreach.trace.play23.filter

import jp.co.bizreach.trace.play23.ZipkinTraceService
import play.api.mvc.{Filter, Headers, RequestHeader, Result}

import scala.concurrent.Future
import scala.util.Failure


class ZipkinTraceFilter extends Filter {

  import ZipkinTraceService.executionContext
  private val reqHeaderToSpanName: RequestHeader => String = ZipkinTraceFilter.ParamAwareRequestNamer

  def apply(nextFilter: (RequestHeader) => Future[Result])(req: RequestHeader): Future[Result] = {
    val serverSpan = ZipkinTraceService.serverReceived(
      spanName = reqHeaderToSpanName(req),
      span = ZipkinTraceService.newSpan(req.headers)((headers, key) => headers.get(key))
    )
    val result = nextFilter(req.copy(headers = new Headers {
      protected val data: Seq[(String, Seq[String])] = {
        req.headers.toMap ++ ZipkinTraceService.toMap(serverSpan).map { case (key, value) => key -> Seq(value) }
      }.toSeq
    }))
    result.onComplete {
      case Failure(t) => ZipkinTraceService.serverSend(serverSpan, "failed" -> s"Finished with exception: ${t.getMessage}")
      case _ => ZipkinTraceService.serverSend(serverSpan)
    }
    result
  }
}

object ZipkinTraceFilter {
  val ParamAwareRequestNamer: RequestHeader => String = { reqHeader =>
    import org.apache.commons.lang3.StringUtils
    val tags = reqHeader.tags
    val pathPattern = StringUtils.replace(tags.getOrElse(play.api.Routes.ROUTE_PATTERN, reqHeader.path), "<[^/]+>", "")
    s"${reqHeader.method} - $pathPattern"
  }
} 
开发者ID:bizreach,项目名称:play-zipkin-tracing,代码行数:41,代码来源:ZipkinTraceFilter.scala


示例11: ZipkinTraceFilter

//设置package包名称以及导入依赖的类
package jp.co.bizreach.trace.play26.filter

import javax.inject.Inject

import akka.stream.Materializer
import jp.co.bizreach.trace.ZipkinTraceServiceLike
import play.api.mvc.{Filter, Headers, RequestHeader, Result}
import play.api.routing.Router

import scala.concurrent.Future
import scala.util.Failure


class ZipkinTraceFilter @Inject() (tracer: ZipkinTraceServiceLike)(implicit val mat: Materializer) extends Filter {

  import tracer.executionContext
  private val reqHeaderToSpanName: RequestHeader => String = ZipkinTraceFilter.ParamAwareRequestNamer

  def apply(nextFilter: (RequestHeader) => Future[Result])(req: RequestHeader): Future[Result] = {
    val serverSpan = tracer.serverReceived(
      spanName = reqHeaderToSpanName(req),
      span = tracer.newSpan(req.headers)((headers, key) => headers.get(key))
    )
    val result = nextFilter(req.withHeaders(new Headers(
      (req.headers.toMap.mapValues(_.headOption getOrElse "") ++ tracer.toMap(serverSpan)).toSeq
    )))
    result.onComplete {
      case Failure(t) => tracer.serverSend(serverSpan, "failed" -> s"Finished with exception: ${t.getMessage}")
      case _ => tracer.serverSend(serverSpan)
    }
    result
  }
}

object ZipkinTraceFilter {
  val ParamAwareRequestNamer: RequestHeader => String = { reqHeader =>
    import org.apache.commons.lang3.StringUtils
    val pathPattern = StringUtils.replace(
      reqHeader.attrs.get(Router.Attrs.HandlerDef).map(_.path).getOrElse(reqHeader.path),
      "<[^/]+>", ""
    )
    s"${reqHeader.method} - $pathPattern"
  }
} 
开发者ID:bizreach,项目名称:play-zipkin-tracing,代码行数:45,代码来源:ZipkinTraceFilter.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Authorization类代码示例发布时间:2022-05-23
下一篇:
Scala GlobalTempViewManager类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap