Fixes bugs introduced by ee62d56cad. Closes #2227.

This commit is contained in:
Dominik Picheta
2015-03-05 21:18:28 +00:00
parent 4e1afdd3e2
commit bab8190b67
2 changed files with 18 additions and 2 deletions

View File

@@ -390,8 +390,11 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
## server takes longer than specified an ETimeout exception will be raised.
var r = if proxy == nil: parseUri(url) else: proxy.url
var headers = substr(httpMethod, len("http"))
# TODO: Use generateHeaders further down once it supports proxies.
if proxy == nil:
headers.add(" " & r.path)
headers.add ' '
if r.path[0] != '/': headers.add '/'
headers.add(r.path)
if r.query.len > 0:
headers.add("?" & r.query)
else:
@@ -567,9 +570,12 @@ proc downloadFile*(url: string, outputFilename: string,
proc generateHeaders(r: Uri, httpMethod: string,
headers: StringTableRef): string =
# TODO: Use this in the blocking HttpClient once it supports proxies.
result = substr(httpMethod, len("http"))
# TODO: Proxies
result.add(" " & r.path)
result.add ' '
if r.path[0] != '/': result.add '/'
result.add(r.path)
if r.query.len > 0:
result.add("?" & r.query)
result.add(" HTTP/1.1\c\L")

View File

@@ -285,6 +285,16 @@ proc `$`*(u: Uri): string =
result.add(u.anchor)
when isMainModule:
block:
let str = "http://localhost"
let test = parseUri(str)
doAssert test.path == ""
block:
let str = "http://localhost/"
let test = parseUri(str)
doAssert test.path == "/"
block:
let str = "http://localhost:8080/test"
let test = parseUri(str)