* Address issue #443. * Address review comments.
This commit is contained in:
parent
6c2ea67512
commit
176d462b07
|
@ -13,7 +13,7 @@ import ../../streams/[asyncstream, tlsstream, chunkstream, boundstream]
|
||||||
import httptable, httpcommon, httpagent, httpbodyrw, multipart
|
import httptable, httpcommon, httpagent, httpbodyrw, multipart
|
||||||
export results, asyncloop, asyncsync, asyncstream, tlsstream, chunkstream,
|
export results, asyncloop, asyncsync, asyncstream, tlsstream, chunkstream,
|
||||||
boundstream, httptable, httpcommon, httpagent, httpbodyrw, multipart,
|
boundstream, httptable, httpcommon, httpagent, httpbodyrw, multipart,
|
||||||
httputils
|
httputils, uri
|
||||||
export SocketFlags
|
export SocketFlags
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -1335,8 +1335,13 @@ proc redirect*(request: HttpClientRequestRef,
|
||||||
if redirectCount > request.session.maxRedirections:
|
if redirectCount > request.session.maxRedirections:
|
||||||
err("Maximum number of redirects exceeded")
|
err("Maximum number of redirects exceeded")
|
||||||
else:
|
else:
|
||||||
|
let headers =
|
||||||
|
block:
|
||||||
|
var res = request.headers
|
||||||
|
res.set(HostHeader, ha.hostname)
|
||||||
|
res
|
||||||
var res = HttpClientRequestRef.new(request.session, ha, request.meth,
|
var res = HttpClientRequestRef.new(request.session, ha, request.meth,
|
||||||
request.version, request.flags, request.headers.toList(), request.buffer)
|
request.version, request.flags, headers.toList(), request.buffer)
|
||||||
res.redirectCount = redirectCount
|
res.redirectCount = redirectCount
|
||||||
ok(res)
|
ok(res)
|
||||||
|
|
||||||
|
@ -1353,8 +1358,14 @@ proc redirect*(request: HttpClientRequestRef,
|
||||||
err("Maximum number of redirects exceeded")
|
err("Maximum number of redirects exceeded")
|
||||||
else:
|
else:
|
||||||
let address = ? request.session.redirect(request.address, uri)
|
let address = ? request.session.redirect(request.address, uri)
|
||||||
|
# Update Host header to redirected URL hostname
|
||||||
|
let headers =
|
||||||
|
block:
|
||||||
|
var res = request.headers
|
||||||
|
res.set(HostHeader, address.hostname)
|
||||||
|
res
|
||||||
var res = HttpClientRequestRef.new(request.session, address, request.meth,
|
var res = HttpClientRequestRef.new(request.session, address, request.meth,
|
||||||
request.version, request.flags, request.headers.toList(), request.buffer)
|
request.version, request.flags, headers.toList(), request.buffer)
|
||||||
res.redirectCount = redirectCount
|
res.redirectCount = redirectCount
|
||||||
ok(res)
|
ok(res)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue