]> git.e2factory.org Git - e2factory.git/commitdiff
Add support for port in URLs
authorrk@emlix.com <rk@emlix.com>
Fri, 8 May 2009 09:08:37 +0000 (11:08 +0200)
committerGordon Hecker <gh@emlix.com>
Tue, 2 Jun 2009 10:21:31 +0000 (12:21 +0200)
Signed-off-by: rk@emlix.com <rainer.keller@emlix.com>
generic/url.lua

index 727c9c6fba3b5997ca9b1ebde20888fb10d1f8b6..a3d913c097e95f3e3ad46c15ac4e475c580e5c37 100644 (file)
@@ -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