"Lua" LWT httpdmodule

Source: Internet
Author: User

To use the HTTPD module, you need to add it at the beginning of the script:

Require "httpd"

  Httpd.pairs (apr_table)

Used to traverse apr_table

 for inch  do body end

Cases:

1Require "httpd"2Local table = {"uri", "protocol", "hostname", "path", "Path_info", "args",3"Method", "filename", "Filedir", "User", "Auth_type",4"Local_ip", "Remote_ip" }5 6Httpd.set_content_type ("Text/plain; Charset=utf8 ")7 8Httpd.write ("Hello Lua world\r\n")9Httpd.write ("----------------------------------\ n")Ten  One  forMM, keyinchIpairs (table) Do AHttpd.write (mm.. "-". Key: "\ r \ n") - End -  theHttpd.write ("----------------------------------")

httpd.set_status (status)

Sets a value from 100 to 599 as the status of the HTTP response.

Httpd.set_content_type (Content_Type)

Sets the content type of the HTTP response to the specified value.

Httpd.set_content_type ("text/html; Charset=utf-8 ");

  Httpd.add_header (name, value [, Err_header])

Adds an HTTP response header, which is a string representing the value of the header.

  Httpd.add_cookie (name [, value [, Expires [, path [, Domain [, secure [, HttpOnly]]] []]

Add a cookie  

  Httpd.write_template (filename [, flags [, file]])

Renders a Web page based on a specified file template

If the template is parsed, the following instruction will be interpreted by the template engine:

Httpd.escape_uri (String)

Escape sequence of characters relative to URI

httpd.escape_xml (String)

Escape string sequence relative to XML

      

Httpd.escape_js (String)

Escape string sequence with respect to JS

      Httpd.input

Used to read the HTTP request data stream, similar to LUA's input

    Httpd.output

Used to output the HTTP response data stream, similar to that of LUA

Httpd.read (...)

Equivalent to Httpd.input:read (...)

Httpd.write (...)

Equivalent to Httpd.output:write (...)

httpd.debug (message)

Writes a message record to the HTTP server debug level in the log

httpd.notice (message)

Writes a message record to the HTTP server notice level in the log

httpd.err (message) 

Write message records to the HTTP server err level in the log

httpd.redirect (Request, URI, status)

Set the location header information and return the status code, when the browser accepts the header information in the Location:xxxx, will automatically jump to xxxx point to the URL address, this jump only browser know, regardless of the contents of the content, the user can not see.

return httpd.redirect (Request, "/next.lua", status)
httpd.dump (value)

Writes value to the HTTP response body, inside the HTML, in the LUA table of the function processing, the ARP table, or recursively

"Lua" LWT httpdmodule

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.