From bab8190b67d074d2adb513e2c2d6f8bb2c4170bd Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 5 Mar 2015 21:18:28 +0000 Subject: [PATCH] Fixes bugs introduced by ee62d56cadb. Closes #2227. --- lib/pure/httpclient.nim | 10 ++++++++-- lib/pure/uri.nim | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 37af14df30..f111015114 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -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") diff --git a/lib/pure/uri.nim b/lib/pure/uri.nim index 9a6e273a88..b0afb75f99 100644 --- a/lib/pure/uri.nim +++ b/lib/pure/uri.nim @@ -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)