標籤:style blog http io color ar os 使用 sp
要使用httpd模組,需要在指令碼開頭添加:
require "httpd"
httpd.pairs(apr_table)
用以遍曆apr_table
for key, value in httpd.pairs(t) do body end
例:
1 require "httpd" 2 local table = { "uri", "protocol", "hostname", "path", "path_info", "args", 3 "method", "filename", "filedir", "user", "auth_type", 4 "local_ip", "remote_ip" } 5 6 httpd.set_content_type("text/plain; charset=utf8") 7 8 httpd.write("Hello Lua World\r\n") 9 httpd.write("----------------------------------\n")10 11 for mm, key in ipairs(table) do12 httpd.write(mm .. "->" .. key .. "\r\n")13 end14 15 httpd.write("----------------------------------")
httpd.set_status (status)
設定一個介於100到599的值作為HTTP響應的狀態。
httpd.set_content_type (content_type)
將HTTP響應的內容類型設定為指定值。
httpd.set_content_type("text/html; charset=utf-8");
httpd.add_header (name, value [, err_header])
添加HTTP回應標頭,值是表示該頭的值的字串。
httpd.add_cookie (name [, value [, expires [, path [, domain [, secure [, httponly]]]]]])
添加cookie
httpd.write_template (filename [, flags [, file]])
根據指定的檔案模版渲染網頁
如果模版被解析,則下面的指令將被模版引擎解釋:
httpd.escape_uri (string)
相對於uri的逸出字元序列
httpd.escape_xml (string)
相對於xml的逸出字元串序列
httpd.escape_js (string)
相對於js的逸出字元串序列
httpd.input
用來讀取HTTP請求資料流,和Lua的input類似
httpd.output
用來輸出HTTP響應資料流,和Lua的output類似
httpd.read(...)
相當於httpd.input:read(....)
httpd.write(...)
相當於httpd.output:write(...)
httpd.debug (message)
將訊息記錄寫入HTTP server debug層級的日誌內
httpd.notice (message)
將訊息記錄寫入HTTP server notice層級的日誌內
httpd.err (message)
將訊息記錄寫入HTTP server err層級的日誌內
httpd.redirect (request, uri, status)
設定Location頭資訊並返回狀態代碼,當瀏覽器接受到頭資訊中的 Location: xxxx 後,就會自動跳轉到 xxxx 指向的URL地址,這個跳轉只有瀏覽器知道,不管體內容裡有沒有東西,使用者都看不到。
return httpd.redirect(request, "/next.lua", status)
httpd.dump (value)
將value寫入至HTTP響應主體、HTML內、函數處理的Lua表中、ARP表或者遞迴
【lua】LWT HttpdModule