* libs/web: Fixed Luci template cache
[project/luci.git] / libs / web / luasrc / http.lua
1 --[[
2 LuCI - HTTP-Interaction
3
4 Description:
5 HTTP-Header manipulator and form variable preprocessor
6
7 FileId:
8 $Id$
9
10 ToDo:
11 - Cookie handling
12
13 License:
14 Copyright 2008 Steven Barth <steven@midlink.org>
15
16 Licensed under the Apache License, Version 2.0 (the "License");
17 you may not use this file except in compliance with the License.
18 You may obtain a copy of the License at
19
20 http://www.apache.org/licenses/LICENSE-2.0
21
22 Unless required by applicable law or agreed to in writing, software
23 distributed under the License is distributed on an "AS IS" BASIS,
24 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 See the License for the specific language governing permissions and
26 limitations under the License.
27
28 ]]--
29
30 module("luci.http", package.seeall)
31
32 if ENV and ENV.HASERLVER then
33 require("luci.sgi.haserl")
34 elseif webuci then
35 require("luci.sgi.webuci")
36 end
37
38 function build_querystring(table)
39 local s="?"
40
41 for k, v in pairs(table) do
42 s = s .. k .. "=" .. v .. "&"
43 end
44
45 return s
46 end
47
48 function urldecode(str)
49 str = str:gsub("+", " ")
50 str = str:gsub("%%(%x%x)",
51 function(h) return string.char(tonumber(h,16)) end)
52 str = str:gsub("\r\n", "\n")
53 return str
54 end
55
56 function urlencode(str)
57 str = str:gsub("\n", "\r\n")
58 str = str:gsub("([^%w ])",
59 function (c) return string.format ("%%%02X", string.byte(c)) end)
60 str = str:gsub(" ", "+")
61 return str
62 end