[英]how to encode httprequest in akka http ? ( Akka http,Scala)
I would like to encode my httprequest (basically encoding httpentity) before sending it to server for processing. 我想先将我的httprequest编码(基本上是对httpentity编码),然后再将其发送到服务器进行处理。
In spray I could do something like this: 在喷雾中,我可以做这样的事情:
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())
}
What would the equivalent be in Akka Http? 在Akka Http中相当于什么? Or in other words, what is the equivalent for encode(encoder) in Akka Http? 换句话说,Akka Http中的encode(encoder)等效于什么?
Thanks 谢谢
我认为encodeResponseWith是您要寻找的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.