Fixes incorrect Host header when using httpclient with proxy.
This commit is contained in:
parent
a01eb098f1
commit
bf4c13711a
1 changed files with 5 additions and 5 deletions
|
|
@ -110,7 +110,7 @@ type
|
||||||
EInvalidProtocol: ProtocolError, EHttpRequestErr: HttpRequestError
|
EInvalidProtocol: ProtocolError, EHttpRequestErr: HttpRequestError
|
||||||
].}
|
].}
|
||||||
|
|
||||||
const defUserAgent* = "Nim httpclient/0.1"
|
const defUserAgent* = "Nim httpclient/" & NimVersion
|
||||||
|
|
||||||
proc httpError(msg: string) =
|
proc httpError(msg: string) =
|
||||||
var e: ref ProtocolError
|
var e: ref ProtocolError
|
||||||
|
|
@ -389,6 +389,7 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
||||||
## | An optional timeout can be specified in milliseconds, if reading from the
|
## | An optional timeout can be specified in milliseconds, if reading from the
|
||||||
## server takes longer than specified an ETimeout exception will be raised.
|
## server takes longer than specified an ETimeout exception will be raised.
|
||||||
var r = if proxy == nil: parseUri(url) else: proxy.url
|
var r = if proxy == nil: parseUri(url) else: proxy.url
|
||||||
|
var hostUrl = if proxy == nil: r else: parseUri(url)
|
||||||
var headers = substr(httpMethod, len("http"))
|
var headers = substr(httpMethod, len("http"))
|
||||||
# TODO: Use generateHeaders further down once it supports proxies.
|
# TODO: Use generateHeaders further down once it supports proxies.
|
||||||
if proxy == nil:
|
if proxy == nil:
|
||||||
|
|
@ -402,10 +403,10 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
||||||
|
|
||||||
headers.add(" HTTP/1.1\c\L")
|
headers.add(" HTTP/1.1\c\L")
|
||||||
|
|
||||||
if r.port == "":
|
if hostUrl.port == "":
|
||||||
add(headers, "Host: " & r.hostname & "\c\L")
|
add(headers, "Host: " & hostUrl.hostname & "\c\L")
|
||||||
else:
|
else:
|
||||||
add(headers, "Host: " & r.hostname & ":" & r.port & "\c\L")
|
add(headers, "Host: " & hostUrl.hostname & ":" & hostUrl.port & "\c\L")
|
||||||
|
|
||||||
if userAgent != "":
|
if userAgent != "":
|
||||||
add(headers, "User-Agent: " & userAgent & "\c\L")
|
add(headers, "User-Agent: " & userAgent & "\c\L")
|
||||||
|
|
@ -414,7 +415,6 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
||||||
add(headers, "Proxy-Authorization: basic " & auth & "\c\L")
|
add(headers, "Proxy-Authorization: basic " & auth & "\c\L")
|
||||||
add(headers, extraHeaders)
|
add(headers, extraHeaders)
|
||||||
add(headers, "\c\L")
|
add(headers, "\c\L")
|
||||||
|
|
||||||
var s = newSocket()
|
var s = newSocket()
|
||||||
if s == nil: raiseOSError(osLastError())
|
if s == nil: raiseOSError(osLastError())
|
||||||
var port = net.Port(80)
|
var port = net.Port(80)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue