diff options
author | adamw <adam@warski.org> | 2017-07-15 10:58:24 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-15 10:58:24 +0200 |
commit | bc685df2cd50814b45e669f4f602732887c2879c (patch) | |
tree | 4df984768865b86b48fbaae7c21f22fd0c3ea079 /akka-http-handler/src/main | |
parent | fdc9b3f9420165cc65c8dd9fe20057a4a12e69c6 (diff) | |
download | sttp-bc685df2cd50814b45e669f4f602732887c2879c.tar.gz sttp-bc685df2cd50814b45e669f4f602732887c2879c.tar.bz2 sttp-bc685df2cd50814b45e669f4f602732887c2879c.zip |
Headers & errors support
Diffstat (limited to 'akka-http-handler/src/main')
-rw-r--r-- | akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala index fc2d632..9125ca3 100644 --- a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala +++ b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala @@ -14,6 +14,7 @@ import com.softwaremill.sttp.model._ import scala.concurrent.Future import scala.util.{Failure, Success, Try} +import scala.collection.immutable.Seq class AkkaHttpSttpHandler(actorSystem: ActorSystem) extends SttpHandler[Future, Source[ByteString, Any]] { @@ -32,7 +33,8 @@ class AkkaHttpSttpHandler(actorSystem: ActorSystem) .flatMap(Http().singleRequest(_)) .flatMap { hr => val code = hr.status.intValue() - bodyFromAkka(responseAs, hr).map(Response(code, _)) + bodyFromAkka(responseAs, hr).map( + Response(_, code, headersFromAkka(hr))) } } @@ -72,6 +74,14 @@ class AkkaHttpSttpHandler(actorSystem: ActorSystem) } } + private def headersFromAkka(hr: HttpResponse): Seq[(String, String)] = { + val ch = ContentTypeHeader -> hr.entity.contentType.toString() + val cl = + hr.entity.contentLengthOption.map(ContentLengthHeader -> _.toString) + val other = hr.headers.map(h => (h.name, h.value)) + ch :: (cl.toList ++ other) + } + private def requestToAkka(r: Request): Future[HttpRequest] = { val ar = HttpRequest(uri = r.uri.toString, method = methodToAkka(r.method)) val parsed = |