Moonshark/runner/lua/http.lua

73 lines
1.4 KiB
Lua

-- http.lua
function http_set_status(code)
__response.status = code
end
function http_set_header(name, value)
__response.headers = __response.headers or {}
__response.headers[name] = value
end
function http_set_content_type(ct)
__response.headers = __response.headers or {}
__response.headers["Content-Type"] = ct
end
function http_set_metadata(key, value)
__response.metadata = __response.metadata or {}
__response.metadata[key] = value
end
function http_redirect(url, status)
__response.status = status or 302
__response.headers = __response.headers or {}
__response.headers["Location"] = url
coroutine.yield("__EXIT__")
end
function send_html(content)
http_set_content_type("text/html")
return content
end
function send_json(content)
http_set_content_type("application/json")
return content
end
function send_text(content)
http_set_content_type("text/plain")
return content
end
function send_xml(content)
http_set_content_type("application/xml")
return content
end
function send_javascript(content)
http_set_content_type("application/javascript")
return content
end
function send_css(content)
http_set_content_type("text/css")
return content
end
function send_svg(content)
http_set_content_type("image/svg+xml")
return content
end
function send_csv(content)
http_set_content_type("text/csv")
return content
end
function send_binary(content, mime_type)
http_set_content_type(mime_type or "application/octet-stream")
return content
end