summaryrefslogtreecommitdiffhomepage
path: root/libs/httpclient
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-12-08 12:13:26 +0000
committerSteven Barth <steven@midlink.org>2009-12-08 12:13:26 +0000
commite8220d96a52be888db8611e2908cb3ba97dfe2f8 (patch)
treee42987c79610f7aa087cec567d34ce6efe21c038 /libs/httpclient
parenta6860ba0c85194f638832de1ce9aa6d27689db08 (diff)
httpclient: Add basic auth support
Diffstat (limited to 'libs/httpclient')
-rw-r--r--libs/httpclient/luasrc/httpclient.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/libs/httpclient/luasrc/httpclient.lua b/libs/httpclient/luasrc/httpclient.lua
index 69abddff3..1f0e55b31 100644
--- a/libs/httpclient/luasrc/httpclient.lua
+++ b/libs/httpclient/luasrc/httpclient.lua
@@ -107,7 +107,14 @@ end
--
function request_raw(uri, options)
options = options or {}
- local pr, host, port, path = uri:match("(%w+)://([%w-.]+):?([0-9]*)(.*)")
+ local pr, auth, host, port, path
+ if uri:find("@") then
+ pr, auth, host, port, path =
+ uri:match("(%w+)://(.+)@([%w-.]+):?([0-9]*)(.*)")
+ else
+ pr, host, port, path = uri:match("(%w+)://([%w-.]+):?([0-9]*)(.*)")
+ end
+
if not host then
return nil, -1, "unable to parse URI"
end
@@ -128,6 +135,10 @@ function request_raw(uri, options)
headers.Connection = "close"
end
+ if auth and not headers.Authorization then
+ headers.Authorization = "Basic " .. nixio.bin.b64encode(auth)
+ end
+
local sock, code, msg = nixio.connect(host, port)
if not sock then
return nil, code, msg