X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libs%2Fweb%2Fluasrc%2Fhttp.lua;h=d34e253a53a8c9a550304270633b59e3770e81e0;hb=595020f919253e56758539d0c7155d490f73bfe6;hp=6b73b9414cf0c129a1596ac4144b64d12fc529da;hpb=ffd5c4ec656bd3f216c66b43587abcfdaf2b5c37;p=oweals%2Fluci.git diff --git a/libs/web/luasrc/http.lua b/libs/web/luasrc/http.lua index 6b73b9414..d34e253a5 100644 --- a/libs/web/luasrc/http.lua +++ b/libs/web/luasrc/http.lua @@ -25,7 +25,7 @@ limitations under the License. ]]-- local ltn12 = require "luci.ltn12" -local proto = require "luci.http.protocol" +local protocol = require "luci.http.protocol" local util = require "luci.util" local string = require "string" local coroutine = require "coroutine" @@ -192,14 +192,16 @@ end --- 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 - header("Vary", "Accept") + header("Content-Type", mime) end - header("Content-Type", mime) end --- Get the RAW HTTP input source @@ -256,6 +258,13 @@ function write(content, src_err) 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)