akka/akka-http

[akka-http, 2.4.8] "Cannot determine request scheme and target endpoint" while using host header in client request level api

Open

#47 opened on Sep 8, 2016

View on GitHub
 (6 comments) (0 reactions) (0 assignees)Scala (598 forks)batch import
1 - triagedhelp wantedt:docs

Repository metrics

Stars
 (1,311 stars)
PR merge metrics
 (Avg merge 1d 10h) (2 merged PRs in 30d)

Description

Issue by alias1 Monday Jul 11, 2016 at 09:53 GMT Originally opened as https://github.com/akka/akka/issues/20934


I'm trying to put together some API abstractions using the request level client API, and running into this error message:

Cannot determine request scheme and target endpoint as HttpMethod(GET) request to /self/calendar doesn't have an absolute URI

I would have expected this should work since I am setting the host header. Cut down example:

# Initial Setup/Abstractions
val http = Http(system)
val hostHeader = headers.Host("api.meetup.com")
val request = HttpRequest().withDefaultHeaders(hostHeader)
val get = request.withMethod(HttpMethods.GET)

# Individual Call
val uri = Uri().withPath(Path("/self/calendar"))
val r = get.withUri(uri)
http.singleRequest(r)

Printing the request:

HttpRequest(HttpMethod(GET),/self/calendar,List(Host: api.meetup.com),HttpEntity.Strict(none/none,ByteString()),HttpProtocol(HTTP/1.1))

I have also tried using the following, to no avail:

  • val request = HttpRequest().withHeaders(hostHeader)
  • val request = HttpRequest().withEffectiveUri(true, hostHeader)
  • .toRelative on the uri chain
  • get.withUri("/self/calendar")

Though if I use val request = get.withUri(uri).withEffectiveUri(true, hostHeader) then the request works.

Am I missing something? Or is there a better way to build up these abstractions? I would have expected that so long as I had the host/effective URL set somewhere in the chain it should work fine.

Contributor guide