Http().singleRequest response header missing

Hi,
I’m using a basic code to make a single request on : “https://json-ld.org/test-suite/tests/compact-0002-in.jsonld

    Http()
      .singleRequest(
        HttpRequest(uri = iri.toString, entity = HttpEntity(ContentTypes.`application/json`, ByteString.empty)))
      .flatMap {
        case resp @ HttpResponse(StatusCodes.OK, _, _, _) =>
          resp.entity.dataBytes.runFold(ByteString(""))(_ ++ _).map { body =>
            println(resp.headers)
            //val links = headers.collect { case `Link`(l) => l }
            val contentType =
              resp.headers.collect { case `Content-Type`(c) => c } match {
                case seq if seq.isEmpty => None
                case seq                => Some(seq.head.mediaType.toString())
              }
            RemoteDocument(None, "", contentType, body.utf8String)
          }
      }

When running, this codes prints the following response headers list:

List(Accept-Ranges: bytes, Access-Control-Allow-Origin: *, Date: Sat, 15 Sep 2018 20:27:41 GMT, ETag: "209fa-157-4c934c92292ae", Last-Modified: Sat, 08 Sep 2012 18:20:56 GMT, Server: Apache/2.2.22 (Ubuntu), Vary: Accept-Encoding)

The same URL retrieve with curl gives:

< HTTP/2 200 
< accept-ranges: bytes
< access-control-allow-origin: *
< content-type: application/ld+json
< date: Sat, 15 Sep 2018 20:35:33 GMT
< etag: "209fa-157-4c934c92292ae"
< last-modified: Sat, 08 Sep 2012 18:20:56 GMT
< server: Apache/2.2.22 (Ubuntu)
< vary: Accept-Encoding
< content-length: 343
< 
...

problem : the content type header (content-type: application/ld+json) is missing from HttpResponse but it appears when using curl. Any idea why this header is not retrieved from akka HttpResponse ?

Hi,
I found out that the content-type header value was available in the HTTP response entity contentType attritube.

Hi nico,

glad you found out. In case, you haven’t seen it, the documentation has a section about special cased headers in akka-http:

https://doc.akka.io/docs/akka-http/current/common/http-model.html#http-headers

Johannes