diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-20 00:24:44 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-20 00:24:44 +0000 |
commit | 53857360bb1ca9cd2080b69d930763ae59db9b06 (patch) | |
tree | 6c1bc6d6462695cf9048801b2244f7fd0cd21ad5 /src/url.lua | |
parent | 7da19138e37c4e0123860f1fecbceb80c3d2627d (diff) | |
download | luasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.tar.gz luasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.tar.bz2 luasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.zip |
Finish port to Lua 5. Everything is working fine.
Still doesn't work in Windows.
Diffstat (limited to 'src/url.lua')
-rw-r--r-- | src/url.lua | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/url.lua b/src/url.lua index 4d2bfa7..2cf9669 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -8,7 +8,7 @@ | |||
8 | ---------------------------------------------------------------------------- | 8 | ---------------------------------------------------------------------------- |
9 | 9 | ||
10 | local Public, Private = {}, {} | 10 | local Public, Private = {}, {} |
11 | URL = Public | 11 | socket.url = Public |
12 | 12 | ||
13 | ----------------------------------------------------------------------------- | 13 | ----------------------------------------------------------------------------- |
14 | -- Parses a url and returns a table with all its parts according to RFC 2396 | 14 | -- Parses a url and returns a table with all its parts according to RFC 2396 |
@@ -28,7 +28,7 @@ URL = Public | |||
28 | -- Obs: | 28 | -- Obs: |
29 | -- the leading '/' in {/<path>} is considered part of <path> | 29 | -- the leading '/' in {/<path>} is considered part of <path> |
30 | ----------------------------------------------------------------------------- | 30 | ----------------------------------------------------------------------------- |
31 | function Public.parse_url(url, default) | 31 | function Public.parse(url, default) |
32 | -- initialize default parameters | 32 | -- initialize default parameters |
33 | local parsed = default or {} | 33 | local parsed = default or {} |
34 | -- empty url is parsed to nil | 34 | -- empty url is parsed to nil |
@@ -70,7 +70,7 @@ end | |||
70 | -- Returns | 70 | -- Returns |
71 | -- a stringing with the corresponding URL | 71 | -- a stringing with the corresponding URL |
72 | ----------------------------------------------------------------------------- | 72 | ----------------------------------------------------------------------------- |
73 | function Public.build_url(parsed) | 73 | function Public.build(parsed) |
74 | local url = parsed.path or "" | 74 | local url = parsed.path or "" |
75 | if parsed.params then url = url .. ";" .. parsed.params end | 75 | if parsed.params then url = url .. ";" .. parsed.params end |
76 | if parsed.query then url = url .. "?" .. parsed.query end | 76 | if parsed.query then url = url .. "?" .. parsed.query end |
@@ -102,9 +102,9 @@ end | |||
102 | -- Returns | 102 | -- Returns |
103 | -- corresponding absolute url | 103 | -- corresponding absolute url |
104 | ----------------------------------------------------------------------------- | 104 | ----------------------------------------------------------------------------- |
105 | function Public.absolute_url(base_url, relative_url) | 105 | function Public.absolute(base_url, relative_url) |
106 | local base = Public.parse_url(base_url) | 106 | local base = Public.parse(base_url) |
107 | local relative = Public.parse_url(relative_url) | 107 | local relative = Public.parse(relative_url) |
108 | if not base then return relative_url | 108 | if not base then return relative_url |
109 | elseif not relative then return base_url | 109 | elseif not relative then return base_url |
110 | elseif relative.scheme then return relative_url | 110 | elseif relative.scheme then return relative_url |
@@ -124,7 +124,7 @@ function Public.absolute_url(base_url, relative_url) | |||
124 | relative.path = Private.absolute_path(base.path,relative.path) | 124 | relative.path = Private.absolute_path(base.path,relative.path) |
125 | end | 125 | end |
126 | end | 126 | end |
127 | return Public.build_url(relative) | 127 | return Public.build(relative) |
128 | end | 128 | end |
129 | end | 129 | end |
130 | 130 | ||
@@ -141,7 +141,7 @@ function Public.parse_path(path) | |||
141 | path = string.gsub(path, "%s", "") | 141 | path = string.gsub(path, "%s", "") |
142 | string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end) | 142 | string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end) |
143 | for i = 1, table.getn(parsed) do | 143 | for i = 1, table.getn(parsed) do |
144 | parsed[i] = Code.unescape(parsed[i]) | 144 | parsed[i] = socket.code.unescape(parsed[i]) |
145 | end | 145 | end |
146 | if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end | 146 | if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end |
147 | if string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 end | 147 | if string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 end |
@@ -201,7 +201,7 @@ function Private.protect_segment(s) | |||
201 | local segment_set = Private.segment_set | 201 | local segment_set = Private.segment_set |
202 | return string.gsub(s, "(%W)", function (c) | 202 | return string.gsub(s, "(%W)", function (c) |
203 | if segment_set[c] then return c | 203 | if segment_set[c] then return c |
204 | else return Code.escape(c) end | 204 | else return socket.code.escape(c) end |
205 | end) | 205 | end) |
206 | end | 206 | end |
207 | 207 | ||