summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2015-09-04 21:25:34 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2015-09-04 21:25:34 +0100
commit37fe21b64ac348e7412c524a8a6e05d4fe6f877c (patch)
tree3ccfbaf015d25ccaa89d7ead38041cf57699bf62 /lib
parent538fc0467b64d67ee9ee3c7967cd2870f667fc0f (diff)
parent619ab0bcf0d4d56a86af88715117aed472edfe70 (diff)
downloadNim-37fe21b64ac348e7412c524a8a6e05d4fe6f877c.tar.gz
Merge pull request #3288 from Snowie/devel
Include port in host header as expected
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/httpclient.nim12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index 98687359b..30b838b7e 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -402,7 +402,11 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
 
   headers.add(" HTTP/1.1\c\L")
 
-  add(headers, "Host: " & parseUri(url).hostname & "\c\L")
+  if r.port == "":
+    add(headers, "Host: " & r.hostname & "\c\L")
+  else:
+    add(headers, "Host: " & r.hostname & ":" & r.port & "\c\L")
+
   if userAgent != "":
     add(headers, "User-Agent: " & userAgent & "\c\L")
   if proxy != nil and proxy.auth != "":
@@ -580,7 +584,11 @@ proc generateHeaders(r: Uri, httpMethod: string,
     result.add("?" & r.query)
   result.add(" HTTP/1.1\c\L")
 
-  add(result, "Host: " & r.hostname & "\c\L")
+  if r.port == "":
+    add(result, "Host: " & r.hostname & "\c\L")
+  else:
+    add(result, "Host: " & r.hostname & ":" & r.port & "\c\L")
+
   add(result, "Connection: Keep-Alive\c\L")
   if body.len > 0 and not headers.hasKey("Content-Length"):
     add(result, "Content-Length: " & $body.len & "\c\L")