From: rk@emlix.com Date: Fri, 8 May 2009 09:08:37 +0000 (+0200) Subject: Add support for port in URLs X-Git-Tag: e2factory-2.3.1pre1~6 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=c2f691e909f4a79c428897001f787482ef5cc0de;p=e2factory.git Add support for port in URLs Signed-off-by: rk@emlix.com --- 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