summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/http
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base/luasrc/http')
-rw-r--r--modules/luci-base/luasrc/http/protocol.lua45
-rw-r--r--modules/luci-base/luasrc/http/protocol.luadoc22
2 files changed, 5 insertions, 62 deletions
diff --git a/modules/luci-base/luasrc/http/protocol.lua b/modules/luci-base/luasrc/http/protocol.lua
index 0a8b2fbab9..096ae46f4a 100644
--- a/modules/luci-base/luasrc/http/protocol.lua
+++ b/modules/luci-base/luasrc/http/protocol.lua
@@ -6,27 +6,10 @@
module("luci.http.protocol", package.seeall)
local ltn12 = require("luci.ltn12")
+local util = require("luci.util")
HTTP_MAX_CONTENT = 1024*8 -- 8 kB maximum content size
--- the "+" sign to " " - and return the decoded string.
-function urldecode( str, no_plus )
-
- local function __chrdec( hex )
- return string.char( tonumber( hex, 16 ) )
- end
-
- if type(str) == "string" then
- if not no_plus then
- str = str:gsub( "+", " " )
- end
-
- str = str:gsub( "%%([a-fA-F0-9][a-fA-F0-9])", __chrdec )
- end
-
- return str
-end
-
-- from given url or string. Returns a table with urldecoded values.
-- Simple parameters are stored as string values associated with the parameter
-- name within the table. Parameters with multiple values are stored as array
@@ -42,8 +25,8 @@ function urldecode_params( url, tbl )
for pair in url:gmatch( "[^&;]+" ) do
-- find key and value
- local key = urldecode( pair:match("^([^=]+)") )
- local val = urldecode( pair:match("^[^=]+=(.+)$") )
+ local key = util.urldecode( pair:match("^([^=]+)") )
+ local val = util.urldecode( pair:match("^[^=]+=(.+)$") )
-- store
if type(key) == "string" and key:len() > 0 then
@@ -62,24 +45,6 @@ function urldecode_params( url, tbl )
return params
end
-function urlencode( str )
-
- local function __chrenc( chr )
- return string.format(
- "%%%02x", string.byte( chr )
- )
- end
-
- if type(str) == "string" then
- str = str:gsub(
- "([^a-zA-Z0-9$_%-%.%~])",
- __chrenc
- )
- end
-
- return str
-end
-
-- separated by "&". Tables are encoded as parameters with multiple values by
-- repeating the parameter name with each value.
function urlencode_params( tbl )
@@ -89,11 +54,11 @@ function urlencode_params( tbl )
if type(v) == "table" then
for i, v2 in ipairs(v) do
enc = enc .. ( #enc > 0 and "&" or "" ) ..
- urlencode(k) .. "=" .. urlencode(v2)
+ util.urlencode(k) .. "=" .. util.urlencode(v2)
end
else
enc = enc .. ( #enc > 0 and "&" or "" ) ..
- urlencode(k) .. "=" .. urlencode(v)
+ util.urlencode(k) .. "=" .. util.urlencode(v)
end
end
diff --git a/modules/luci-base/luasrc/http/protocol.luadoc b/modules/luci-base/luasrc/http/protocol.luadoc
index 19a0a3419b..cf3d5b2d2f 100644
--- a/modules/luci-base/luasrc/http/protocol.luadoc
+++ b/modules/luci-base/luasrc/http/protocol.luadoc
@@ -7,18 +7,6 @@ decoding and to retrive form data from raw http messages.
module "luci.http.protocol"
---[[
-Decode an urlencoded string - optionally without decoding
-
-the "+" sign to " " - and return the decoded string.
-@class function
-@name urldecode
-@param str Input string in x-www-urlencoded format
-@param no_plus Don't decode "+" signs to spaces
-@return The decoded string
-@see urlencode
-]]
-
----[[
Extract and split urlencoded data pairs, separated bei either "&" or ";"
from given url or string. Returns a table with urldecoded values.
@@ -34,16 +22,6 @@ containing the corresponding values.
]]
---[[
-Encode given string to x-www-urlencoded format.
-
-@class function
-@name urlencode
-@param str String to encode
-@return String containing the encoded data
-@see urldecode
-]]
-
----[[
Encode each key-value-pair in given table to x-www-urlencoded format,
separated by "&". Tables are encoded as parameters with multiple values by