【lua】LWT HttpdModule

编程入门 行业动态 更新时间:2024-10-11 19:24:03

【<a href=https://www.elefans.com/category/jswz/34/1770288.html style=lua】LWT HttpdModule"/>

【lua】LWT HttpdModule

要使用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) do
12         httpd.write(mm .. "->" .. key .. "\r\n")
13 end
14 
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表或者递归

转载于:.html

更多推荐

【lua】LWT HttpdModule

本文发布于:2024-03-06 05:19:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1714468.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:lua   LWT   HttpdModule

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!