Reputation: 1178
I would like to encode my httprequest (basically encoding httpentity) before sending it to server for processing.
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? Or in other words, what is the equivalent for encode(encoder) in Akka Http?
Thanks
Upvotes: 0
Views: 277