akka / 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 6 comments 0 reactions 0 assignees View on GitHub
1 - triaged help wanted t:docs
Dominant language
Scala
Stars
1.4k
Forks
584
Avg merge
14h 33m
Merged PRs (30d)
24

Description

**Issue by [alias1](https://github.com/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

Open the contributing guide

Research direction

Start with the request-level client API and the HttpRequest.withEffectiveUri and singleRequest calls shown in the reproducer. Run the example with a Host header and a relative URI, then compare it with the working withEffectiveUri variant. Done means determining whether the documented request construction should accept this form or clearly explaining the required URI handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.