diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2002-07-08 21:01:45 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2002-07-08 21:01:45 +0000 |
commit | 5b2a124305f26d36e95b639b1c70a32368f03261 (patch) | |
tree | 6b34fb2c047b2b88cea89b2b3aa87f546fef726d /src/url.lua | |
parent | 60e7bf48b077377c11022f34e24bbbfb596397bf (diff) | |
download | luasocket-5b2a124305f26d36e95b639b1c70a32368f03261.tar.gz luasocket-5b2a124305f26d36e95b639b1c70a32368f03261.tar.bz2 luasocket-5b2a124305f26d36e95b639b1c70a32368f03261.zip |
Updated for Lua 4.1-w3.
Diffstat (limited to 'src/url.lua')
-rw-r--r-- | src/url.lua | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/url.lua b/src/url.lua index 673c9ac..e17bcf5 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- URI parsing, composition and relative URL resolution | 2 | -- URI parsing, composition and relative URL resolution |
3 | -- LuaSocket 1.4 toolkit. | 3 | -- LuaSocket 1.5 toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Date: 20/7/2001 | 5 | -- Date: 20/7/2001 |
6 | -- Conforming to: RFC 2396, LTN7 | 6 | -- Conforming to: RFC 2396, LTN7 |
@@ -36,24 +36,24 @@ function Public.parse_url(url, default) | |||
36 | -- remove whitespace | 36 | -- remove whitespace |
37 | url = gsub(url, "%s", "") | 37 | url = gsub(url, "%s", "") |
38 | -- get fragment | 38 | -- get fragment |
39 | url = gsub(url, "#(.*)$", function(f) %parsed.fragment = f end) | 39 | url = gsub(url, "#(.*)$", function(f) parsed.fragment = f end) |
40 | -- get scheme | 40 | -- get scheme |
41 | url = gsub(url, "^([%w][%w%+%-%.]*)%:", function(s) %parsed.scheme = s end) | 41 | url = gsub(url, "^([%w][%w%+%-%.]*)%:", function(s) parsed.scheme = s end) |
42 | -- get authority | 42 | -- get authority |
43 | url = gsub(url, "^//([^/]*)", function(n) %parsed.authority = n end) | 43 | url = gsub(url, "^//([^/]*)", function(n) parsed.authority = n end) |
44 | -- get query string | 44 | -- get query string |
45 | url = gsub(url, "%?(.*)", function(q) %parsed.query = q end) | 45 | url = gsub(url, "%?(.*)", function(q) parsed.query = q end) |
46 | -- get params | 46 | -- get params |
47 | url = gsub(url, "%;(.*)", function(p) %parsed.params = p end) | 47 | url = gsub(url, "%;(.*)", function(p) parsed.params = p end) |
48 | if url ~= "" then parsed.path = url end | 48 | if url ~= "" then parsed.path = url end |
49 | local authority = parsed.authority | 49 | local authority = parsed.authority |
50 | if not authority then return parsed end | 50 | if not authority then return parsed end |
51 | authority = gsub(authority,"^([^@]*)@",function(u) %parsed.userinfo = u end) | 51 | authority = gsub(authority,"^([^@]*)@",function(u) parsed.userinfo = u end) |
52 | authority = gsub(authority, ":([^:]*)$", function(p) %parsed.port = p end) | 52 | authority = gsub(authority, ":([^:]*)$", function(p) parsed.port = p end) |
53 | if authority ~= "" then parsed.host = authority end | 53 | if authority ~= "" then parsed.host = authority end |
54 | local userinfo = parsed.userinfo | 54 | local userinfo = parsed.userinfo |
55 | if not userinfo then return parsed end | 55 | if not userinfo then return parsed end |
56 | userinfo = gsub(userinfo, ":([^:]*)$", function(p) %parsed.password = p end) | 56 | userinfo = gsub(userinfo, ":([^:]*)$", function(p) parsed.password = p end) |
57 | parsed.user = userinfo | 57 | parsed.user = userinfo |
58 | return parsed | 58 | return parsed |
59 | end | 59 | end |
@@ -99,8 +99,8 @@ end | |||
99 | -- corresponding absolute url | 99 | -- corresponding absolute url |
100 | ----------------------------------------------------------------------------- | 100 | ----------------------------------------------------------------------------- |
101 | function Public.absolute_url(base_url, relative_url) | 101 | function Public.absolute_url(base_url, relative_url) |
102 | local base = %Public.parse_url(base_url) | 102 | local base = Public.parse_url(base_url) |
103 | local relative = %Public.parse_url(relative_url) | 103 | local relative = Public.parse_url(relative_url) |
104 | if not base then return relative_url | 104 | if not base then return relative_url |
105 | elseif not relative then return base_url | 105 | elseif not relative then return base_url |
106 | elseif relative.scheme then return relative_url | 106 | elseif relative.scheme then return relative_url |
@@ -117,10 +117,10 @@ function Public.absolute_url(base_url, relative_url) | |||
117 | end | 117 | end |
118 | end | 118 | end |
119 | else | 119 | else |
120 | relative.path = %Private.absolute_path(base.path,relative.path) | 120 | relative.path = Private.absolute_path(base.path,relative.path) |
121 | end | 121 | end |
122 | end | 122 | end |
123 | return %Public.build_url(relative) | 123 | return Public.build_url(relative) |
124 | end | 124 | end |
125 | end | 125 | end |
126 | 126 | ||
@@ -135,7 +135,7 @@ function Public.parse_path(path) | |||
135 | local parsed = {} | 135 | local parsed = {} |
136 | path = path or "" | 136 | path = path or "" |
137 | path = gsub(path, "%s", "") | 137 | path = gsub(path, "%s", "") |
138 | gsub(path, "([^/]+)", function (s) tinsert(%parsed, s) end) | 138 | gsub(path, "([^/]+)", function (s) tinsert(parsed, s) end) |
139 | for i = 1, getn(parsed) do | 139 | for i = 1, getn(parsed) do |
140 | parsed[i] = Code.unescape(parsed[i]) | 140 | parsed[i] = Code.unescape(parsed[i]) |
141 | end | 141 | end |
@@ -166,11 +166,11 @@ function Public.build_path(parsed, unsafe) | |||
166 | end | 166 | end |
167 | else | 167 | else |
168 | for i = 1, n-1 do | 168 | for i = 1, n-1 do |
169 | path = path .. %Private.protect_segment(parsed[i]) | 169 | path = path .. Private.protect_segment(parsed[i]) |
170 | path = path .. "/" | 170 | path = path .. "/" |
171 | end | 171 | end |
172 | if n > 0 then | 172 | if n > 0 then |
173 | path = path .. %Private.protect_segment(parsed[n]) | 173 | path = path .. Private.protect_segment(parsed[n]) |
174 | if parsed.is_directory then path = path .. "/" end | 174 | if parsed.is_directory then path = path .. "/" end |
175 | end | 175 | end |
176 | end | 176 | end |
@@ -194,9 +194,9 @@ Private.segment_set = Private.make_set { | |||
194 | } | 194 | } |
195 | 195 | ||
196 | function Private.protect_segment(s) | 196 | function Private.protect_segment(s) |
197 | local segment_set = %Private.segment_set | 197 | local segment_set = Private.segment_set |
198 | return gsub(s, "(%W)", function (c) | 198 | return gsub(s, "(%W)", function (c) |
199 | if %segment_set[c] then return c | 199 | if segment_set[c] then return c |
200 | else return Code.escape(c) end | 200 | else return Code.escape(c) end |
201 | end) | 201 | end) |
202 | end | 202 | end |