When redirecting with httpclient.redirect, the new request inherits the original request's headers, so if the hostname of the redirection destination is different from the original hostname, the request will be invalid.
import chronos
import chronos/apps/http/[httptable, httpcommon, httpclient]
import std/uri
proc main {.async.} =
let req = HttpClientRequestRef.get(
HttpSessionRef.new(), "https://api.github.com/repos/status-im/nim-chronos/zipball/master").tryGet()
let resp = await req.send()
doAssert resp.status == 302
# BUG HERE
let redirect = req.redirect(resp.getNewLocation().tryGet()).tryGet()
echo redirect.address.hostname # -> codeload.github.com
echo redirect.headers.getString(HostHeader) # -> api.github.com
await resp.closeWait()
await req.closeWait()
# let (status, data) = await redirect.fetch()
# await redirect.closeWait()
# echo status # -> 400 bad request
waitFor main()
When redirecting with
httpclient.redirect
, the new request inherits the original request's headers, so if the hostname of the redirection destination is different from the original hostname, the request will be invalid.