aboutsummaryrefslogtreecommitdiff
path: root/akka-http-handler
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-08-29 13:08:56 +0200
committeradamw <adam@warski.org>2017-08-29 13:08:56 +0200
commit36adc7902a8ce64c654637df6934e482397eeaed (patch)
tree259bd8758431be76bd0e4ccd322116a15cc52751 /akka-http-handler
parent75a010d974aac96e8c96d34e38590c219cdca900 (diff)
downloadsttp-36adc7902a8ce64c654637df6934e482397eeaed.tar.gz
sttp-36adc7902a8ce64c654637df6934e482397eeaed.tar.bz2
sttp-36adc7902a8ce64c654637df6934e482397eeaed.zip
Filtering out the content-length header in Akka, as it cannot be explicitly set
Diffstat (limited to 'akka-http-handler')
-rw-r--r--akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala16
1 files changed, 14 insertions, 2 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 b296e5c..286289e 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
@@ -7,7 +7,11 @@ import akka.http.scaladsl.Http
import akka.http.scaladsl.coding.{Deflate, Gzip, NoCoding}
import akka.http.scaladsl.model.HttpHeader.ParsingResult
import akka.http.scaladsl.model.{Multipart => AkkaMultipart, _}
-import akka.http.scaladsl.model.headers.{HttpEncodings, `Content-Type`}
+import akka.http.scaladsl.model.headers.{
+ HttpEncodings,
+ `Content-Type`,
+ `Content-Length`
+}
import akka.http.scaladsl.model.ContentTypes.`application/octet-stream`
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{FileIO, Source, StreamConverters}
@@ -115,8 +119,13 @@ class AkkaHttpSttpHandler private (actorSystem: ActorSystem,
private def headersToAkka(
headers: Seq[(String, String)]): Try[Seq[HttpHeader]] = {
+ // content-type and content-length headers have to be set via the body
+ // entity, not as headers
val parsed =
- headers.filterNot(isContentType).map(h => HttpHeader.parse(h._1, h._2))
+ headers
+ .filterNot(isContentType)
+ .filterNot(isContentLength)
+ .map(h => HttpHeader.parse(h._1, h._2))
val errors = parsed.collect {
case ParsingResult.Error(e) => e
}
@@ -225,6 +234,9 @@ class AkkaHttpSttpHandler private (actorSystem: ActorSystem,
private def isContentType(header: (String, String)) =
header._1.toLowerCase.contains(`Content-Type`.lowercaseName)
+ private def isContentLength(header: (String, String)) =
+ header._1.toLowerCase.contains(`Content-Length`.lowercaseName)
+
// http://doc.akka.io/docs/akka-http/10.0.7/scala/http/common/de-coding.html
private def decodeAkkaResponse(response: HttpResponse): HttpResponse = {
val decoder = response.encoding match {