akka/akka-http

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

开放

#47 创建于 2016年9月8日

 (6 条评论) (0 个反应) (0 位负责人)Scala (598 个派生)batch import
1 - triagedhelp wantedt:docs

仓库指标

星标
 (1,311 个星标)
PR 合并指标
 (平均合并 1天 10小时) (30 天内合并 2 个 PR)

描述

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.

贡献者指南