From c2f691e909f4a79c428897001f787482ef5cc0de Mon Sep 17 00:00:00 2001 From: "rk@emlix.com" Date: Fri, 8 May 2009 11:08:37 +0200 Subject: [PATCH] Add support for port in URLs Signed-off-by: rk@emlix.com --- generic/url.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/generic/url.lua b/generic/url.lua index 727c9c6..a3d913c 100644 --- a/generic/url.lua +++ b/generic/url.lua @@ -41,6 +41,7 @@ function parse(url) -- @field servername the server name from the server part -- @field user the user name from the server part (optional) -- @field pass the password from the server part (optional) + -- @field port given server port (optional) if not url then return nil, "missing parameter: url" end @@ -49,7 +50,7 @@ function parse(url) u.transport, u.server, u.path = u.url:match("(%S+)://([^/]*)(%S*)") if not u.transport then - return nil, "can't parse url" + return nil, string.format("can't parse url: %s", url) end -- remove leading slashes from the path u.path = u.path:match("^[/]*(%S*)") @@ -64,6 +65,11 @@ function parse(url) else u.servername = u.server end + if u.server:match(":(%d+)$") then + u.port = u.server:match(":(%d+)$") + u.server = string.gsub(u.server, ":%d+$","") -- Remove port from server string. + u.servername = string.gsub(u.servername, ":%d+$","") -- Remove port from server string. + end return u, nil end -- 2.39.5