libs/web: Made luci.http.write a sink
This commit is contained in:
parent
9fd9401d9b
commit
9b1ef9e2b1
1 changed files with 22 additions and 13 deletions
|
@ -169,22 +169,31 @@ function status(code, message)
|
||||||
coroutine.yield(1, code, message)
|
coroutine.yield(1, code, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
function write(content)
|
function write(content, src_err)
|
||||||
if not content or #content == 0 then
|
if not content then
|
||||||
return
|
if src_err then
|
||||||
end
|
error(src_err)
|
||||||
if not context.eoh then
|
else
|
||||||
if not context.status then
|
close()
|
||||||
status()
|
|
||||||
end
|
end
|
||||||
if not context.headers or not context.headers["content-type"] then
|
return true
|
||||||
header("Content-Type", "text/html; charset=utf-8")
|
elseif #content == 0 then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
if not context.eoh then
|
||||||
|
if not context.status then
|
||||||
|
status()
|
||||||
|
end
|
||||||
|
if not context.headers or not context.headers["content-type"] then
|
||||||
|
header("Content-Type", "text/html; charset=utf-8")
|
||||||
|
end
|
||||||
|
|
||||||
|
context.eoh = true
|
||||||
|
coroutine.yield(3)
|
||||||
end
|
end
|
||||||
|
coroutine.yield(4, content)
|
||||||
context.eoh = true
|
return true
|
||||||
coroutine.yield(3)
|
|
||||||
end
|
end
|
||||||
coroutine.yield(4, content)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function redirect(url)
|
function redirect(url)
|
||||||
|
|
Loading…
Reference in a new issue