【问题标题】:how to encode httprequest in akka http ? ( Akka http,Scala)如何在akka http中编码httprequest? (阿卡 http,斯卡拉)
【发布时间】:2017-10-16 00:00:11
【问题描述】:

我想在发送到服务器进行处理之前对我的 httprequest(基本上编码 httpentity)进行编码。

在喷雾中我可以这样做:

import spray.http.HttpHeaders.RawHeader
import spray.http.parser.HttpParser
import akka.actor._
import spray.http.{HttpEntity, HttpMethods, HttpRequest, HttpResponse}
import spray.httpx.RequestBuilding
import spray.httpx.RequestBuilding.{encode, logRequest}
import spray.httpx.encoding.{Deflate, Gzip}

object AddHeaderSpray01 extends App {

  def actorRefFactory = ActorSystem("akkaclient01")

  val myheader = RawHeader("User-Agent", "bluberry")

  val modifiedheader = RequestBuilding.addHeader(HttpParser.parseHeader(myheader).left.flatMap(_ ⇒ Right(myheader)).right.get)

  val myentity = HttpEntity("this is the request body you are currently looking at")


  val myrequest = HttpRequest(HttpMethods.GET,"www.google.com",List(),myentity)

  val modifiedrequest = modifiedheader(myrequest)


 def tempPipeline : HttpRequest => HttpRequest =
   {
      encode(Gzip)
 }
  println(tempPipeline(myrequest).toString())
}

Akka Http 中的等价物是什么?或者换句话说,Akka Http 中 encode(encoder) 的等价物是什么?

谢谢

【问题讨论】:

    标签: scala akka spray


    【解决方案1】:

    我认为encodeResponseWith 就是您要找的东西

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-12
      • 2012-03-17
      相关资源
      最近更新 更多