mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-01 10:12:27 +00:00
Make major improvements to redbean
- lua server pages - lua http library - http v0.9 support - request uri parsing - fork failure recovery - accelerated redirects - http pipelining support - lenient message framing - html / uri / js escaping - fix shutdown signal handling
This commit is contained in:
parent
6b90ff60cd
commit
09bcfa23d5
23 changed files with 2208 additions and 581 deletions
|
@ -1,7 +1,48 @@
|
|||
send('HTTP/1.1 200 OK\r\n'..
|
||||
'Date: ' .. date() .. '\r\n'..
|
||||
'Server: redbean/0.1\r\n'..
|
||||
'Content-Type: text/plain\r\n'..
|
||||
'Content-Length: 7\r\n'..
|
||||
'\r\n'..
|
||||
'hello\r\n')
|
||||
-- redbean lua server page demo
|
||||
|
||||
local function main()
|
||||
-- This check is optional.
|
||||
-- We do this by default if you don't call GetMethod().
|
||||
if GetMethod() ~= 'GET' and GetMethod() ~= 'HEAD' then
|
||||
ServeError(405)
|
||||
SetHeader('Allow', 'GET, HEAD')
|
||||
return
|
||||
end
|
||||
|
||||
-- These two lines are optional.
|
||||
-- The default behavior is to do this if you don't.
|
||||
SetStatus(200) -- Shorthand for SetStatus(200, "OK")
|
||||
SetHeader('Content-Type', 'text/html; charset=utf-8')
|
||||
|
||||
-- Response data is buffered until the script finishes running.
|
||||
-- Compression is applied automatically, based on your headers.
|
||||
Write('<!doctype html>\n')
|
||||
Write('<title>redbean</title>\n')
|
||||
Write('<h1>redbean lua server page demo</h1>\n')
|
||||
|
||||
-- GetParams() returns an ordered list of Request-URI query params.
|
||||
Write('<h3>request uri parameters</h3>\n')
|
||||
params = GetParams()
|
||||
if #params > 0 then
|
||||
Write('<dl>\n')
|
||||
for i = 1,#params do
|
||||
Write('<dt>')
|
||||
Write(EscapeHtml(params[i][1]))
|
||||
Write('\n')
|
||||
if params[i][2] then
|
||||
Write('<dd>')
|
||||
Write(EscapeHtml(params[i][2]))
|
||||
Write('\n')
|
||||
end
|
||||
end
|
||||
Write('</dl>\n')
|
||||
else
|
||||
Write('<p>\n')
|
||||
Write('<em>none</em><br>\n')
|
||||
Write('ProTip: Try <a href="')
|
||||
Write(EscapeHtml(EscapePath(GetPath()) .. '?x=hi+there&y&z&z=' .. EscapeParam('&')))
|
||||
Write('">clicking here</a>!\n')
|
||||
end
|
||||
end
|
||||
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue