0
我希望在將它發送到服務器進行處理之前對我的httprequest(基本上是編碼httpentity)進行編碼。如何在akka http中編碼httprequest? (Akka http,Scala)
在噴我可以做這樣的事情:
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())
}
就相當於是什麼在阿卡的Http?或者換句話說,Akka Http中的編碼器(編碼器)等效於什麼?
感謝