projects
/
oweals
/
luci.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
libs/web: rework DynamicList widget
[oweals/luci.git]
/
libs
/
web
/
luasrc
/
http.lua
diff --git
a/libs/web/luasrc/http.lua
b/libs/web/luasrc/http.lua
index b1ffac2bef4efba55d16b08e6c464316f89feda7..d34e253a53a8c9a550304270633b59e3770e81e0 100644
(file)
--- a/
libs/web/luasrc/http.lua
+++ b/
libs/web/luasrc/http.lua
@@
-24,15
+24,20
@@
limitations under the License.
]]--
]]--
+local ltn12 = require "luci.ltn12"
+local protocol = require "luci.http.protocol"
+local util = require "luci.util"
+local string = require "string"
+local coroutine = require "coroutine"
+
+local pairs, tostring, error = pairs, tostring, error
+
--- LuCI Web Framework high-level HTTP functions.
--- LuCI Web Framework high-level HTTP functions.
-module("luci.http", package.seeall)
-local ltn12 = require("luci.ltn12")
-require("luci.http.protocol")
-require("luci.util")
+module "luci.http"
-context =
luci.
util.threadlocal()
+context = util.threadlocal()
-Request =
luci.
util.class()
+Request = util.class()
function Request.__init__(self, env, sourcein, sinkerr)
self.input = sourcein
self.error = sinkerr
function Request.__init__(self, env, sourcein, sinkerr)
self.input = sourcein
self.error = sinkerr
@@
-45,7
+50,7
@@
function Request.__init__(self, env, sourcein, sinkerr)
self.message = {
env = env,
headers = {},
self.message = {
env = env,
headers = {},
- params =
luci.http.
protocol.urldecode_params(env.QUERY_STRING or ""),
+ params = protocol.urldecode_params(env.QUERY_STRING or ""),
}
self.parsed_input = false
}
self.parsed_input = false
@@
-109,7
+114,7
@@
function Request.setfilehandler(self, callback)
end
function Request._parse_input(self)
end
function Request._parse_input(self)
-
luci.http.
protocol.parse_message_body(
+ protocol.parse_message_body(
self.input,
self.message,
self.filehandler
self.input,
self.message,
self.filehandler
@@
-187,14
+192,16
@@
end
--- Set the mime type of following content data.
-- @param mime Mimetype of following content
function prepare_content(mime)
--- Set the mime type of following content data.
-- @param mime Mimetype of following content
function prepare_content(mime)
- if mime == "application/xhtml+xml" then
- if not getenv("HTTP_ACCEPT") or
- not getenv("HTTP_ACCEPT"):find("application/xhtml+xml", nil, true) then
- mime = "text/html; charset=UTF-8"
+ if not context.headers or not context.headers["content-type"] then
+ if mime == "application/xhtml+xml" then
+ if not getenv("HTTP_ACCEPT") or
+ not getenv("HTTP_ACCEPT"):find("application/xhtml+xml", nil, true) then
+ mime = "text/html; charset=UTF-8"
+ end
+ header("Vary", "Accept")
end
end
- header("
Vary", "Accept"
)
+ header("
Content-Type", mime
)
end
end
- header("Content-Type", mime)
end
--- Get the RAW HTTP input source
end
--- Get the RAW HTTP input source
@@
-251,6
+258,13
@@
function write(content, src_err)
end
end
end
end
+--- Splice data from a filedescriptor to the client.
+-- @param fp File descriptor
+-- @param size Bytes to splice (optional)
+function splice(fd, size)
+ coroutine.yield(6, fd, size)
+end
+
--- Redirects the client to a new URL and closes the connection.
-- @param url Target URL
function redirect(url)
--- Redirects the client to a new URL and closes the connection.
-- @param url Target URL
function redirect(url)
@@
-277,10
+291,10
@@
end
-- @param no_plus Don't decode + to " "
-- @return URL-decoded string
-- @see urlencode
-- @param no_plus Don't decode + to " "
-- @return URL-decoded string
-- @see urlencode
-urldecode =
luci.http.
protocol.urldecode
+urldecode = protocol.urldecode
--- Return the URL-encoded equivalent of a string.
-- @param str Source string
-- @return URL-encoded string
-- @see urldecode
--- Return the URL-encoded equivalent of a string.
-- @param str Source string
-- @return URL-encoded string
-- @see urldecode
-urlencode =
luci.http.
protocol.urlencode
+urlencode = protocol.urlencode