【lua】LWT HttpdModule

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.