1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5 <title>Reference</title>
6 <link rel="stylesheet" href="../luadoc.css" type="text/css" />
7 <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
14 <div id="product_logo"></div>
15 <div id="product_name"><big><b></b></big></div>
16 <div id="product_description"></div>
17 </div> <!-- id="product" -->
27 <li><a href="../index.html">Index</a></li>
38 <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
41 <li><strong>luci.http</strong></li>
44 <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
48 <a href="../modules/luci.http.date.html">luci.http.date</a>
52 <a href="../modules/luci.http.mime.html">luci.http.mime</a>
56 <a href="../modules/luci.i18n.html">luci.i18n</a>
60 <a href="../modules/luci.ip.html">luci.ip</a>
64 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
68 <a href="../modules/luci.json.html">luci.json</a>
72 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
76 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
80 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
84 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
88 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
92 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
96 <a href="../modules/luci.sys.html">luci.sys</a>
100 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
104 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
108 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
112 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
116 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
120 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
124 <a href="../modules/luci.util.html">luci.util</a>
128 <a href="../modules/nixio.html">nixio</a>
132 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
136 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
140 <a href="../modules/nixio.File.html">nixio.File</a>
144 <a href="../modules/nixio.README.html">nixio.README</a>
148 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
152 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
156 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
160 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
164 <a href="../modules/nixio.bin.html">nixio.bin</a>
168 <a href="../modules/nixio.bit.html">nixio.bit</a>
172 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
176 <a href="../modules/nixio.fs.html">nixio.fs</a>
191 </div><!-- id="navigation" -->
195 <h1>Class <code>luci.http</code></h1>
206 <table class="function_list">
209 <td class="name" nowrap><a href="#build_querystring">build_querystring</a> (table)</td>
212 Create a querystring out of a table of key - value pairs.</td>
216 <td class="name" nowrap><a href="#close">close</a> ()</td>
219 Close the HTTP-Connection.</td>
223 <td class="name" nowrap><a href="#content">content</a> ()</td>
226 Return the request content if the request was of unknown type.</td>
230 <td class="name" nowrap><a href="#formvalue">formvalue</a> (name, noparse)</td>
233 Get a certain HTTP input value or a table of all input values.</td>
237 <td class="name" nowrap><a href="#formvaluetable">formvaluetable</a> (prefix)</td>
240 Get a table of all HTTP input values with a certain prefix.</td>
244 <td class="name" nowrap><a href="#getcookie">getcookie</a> (name)</td>
247 Get the value of a certain HTTP-Cookie.</td>
251 <td class="name" nowrap><a href="#getenv">getenv</a> (name)</td>
254 Get the value of a certain HTTP environment variable
255 or the environment table itself.</td>
259 <td class="name" nowrap><a href="#header">header</a> (key, value)</td>
262 Send a HTTP-Header.</td>
266 <td class="name" nowrap><a href="#mimedecode_message_body">mimedecode_message_body</a> (src, msg, filecb)</td>
269 Decode a mime encoded http message body with multipart/form-data Content-Type.</td>
273 <td class="name" nowrap><a href="#parse_message_body">parse_message_body</a> (src, msg, filecb)</td>
276 Try to extract and decode a http message body from the given ltn12 source.</td>
280 <td class="name" nowrap><a href="#prepare_content">prepare_content</a> (mime)</td>
283 Set the mime type of following content data.</td>
287 <td class="name" nowrap><a href="#redirect">redirect</a> (url)</td>
290 Redirects the client to a new URL and closes the connection.</td>
294 <td class="name" nowrap><a href="#setfilehandler">setfilehandler</a> (callback)</td>
297 Set a handler function for incoming user file uploads.</td>
301 <td class="name" nowrap><a href="#source">source</a> ()</td>
304 Get the RAW HTTP input source
309 <td class="name" nowrap><a href="#splice">splice</a> (fp, size)</td>
312 Splice data from a filedescriptor to the client.</td>
316 <td class="name" nowrap><a href="#status">status</a> (code, message)</td>
319 Set the HTTP status code and status message.</td>
323 <td class="name" nowrap><a href="#urldecode">urldecode</a> (str, no_plus)</td>
326 Return the URL-decoded equivalent of a string.</td>
330 <td class="name" nowrap><a href="#urldecode_message_body">urldecode_message_body</a> (src, msg)</td>
333 Decode an urlencoded http message body with application/x-www-urlencoded
338 <td class="name" nowrap><a href="#urldecode_params">urldecode_params</a> (url, tbl)</td>
341 Extract and split urlencoded data pairs, separated bei either "&" or ";"
342 from given url or string.</td>
346 <td class="name" nowrap><a href="#urlencode">urlencode</a> (str)</td>
349 Return the URL-encoded equivalent of a string.</td>
353 <td class="name" nowrap><a href="#urlencode_params">urlencode_params</a> (tbl)</td>
356 Encode each key-value-pair in given table to x-www-urlencoded format,
357 separated by "&".</td>
361 <td class="name" nowrap><a href="#write">write</a> (content, src_err)</td>
364 Send a chunk of content data to the client.</td>
368 <td class="name" nowrap><a href="#write_json">write_json</a> (data)</td>
371 Send the given data as JSON encoded string.</td>
385 <h2><a name="functions"></a>Functions</h2>
386 <dl class="function">
390 <dt><a name="build_querystring"></a><strong>build_querystring</strong> (table)</dt>
394 Create a querystring out of a table of key - value pairs.
402 table: Query string source table
412 <h3>Return value:</h3>
413 Encoded HTTP query string
422 <dt><a name="close"></a><strong>close</strong> ()</dt>
426 Close the HTTP-Connection.
442 <dt><a name="content"></a><strong>content</strong> ()</dt>
446 Return the request content if the request was of unknown type.
455 <h3>Return values:</h3>
458 <li>HTTP request body
460 <li>HTTP request body length
471 <dt><a name="formvalue"></a><strong>formvalue</strong> (name, noparse)</dt>
475 Get a certain HTTP input value or a table of all input values.
483 name: Name of the GET or POST variable to fetch
487 noparse: Don't parse POST data before getting the value
497 <h3>Return value:</h3>
498 HTTP input value or table of all input value
507 <dt><a name="formvaluetable"></a><strong>formvaluetable</strong> (prefix)</dt>
511 Get a table of all HTTP input values with a certain prefix.
529 <h3>Return value:</h3>
530 Table of all HTTP input values with given prefix
539 <dt><a name="getcookie"></a><strong>getcookie</strong> (name)</dt>
543 Get the value of a certain HTTP-Cookie.
561 <h3>Return value:</h3>
562 String containing cookie data
571 <dt><a name="getenv"></a><strong>getenv</strong> (name)</dt>
575 Get the value of a certain HTTP environment variable
576 or the environment table itself.
584 name: Environment variable
594 <h3>Return value:</h3>
595 HTTP environment value or environment table
604 <dt><a name="header"></a><strong>header</strong> (key, value)</dt>
637 <dt><a name="mimedecode_message_body"></a><strong>mimedecode_message_body</strong> (src, msg, filecb)</dt>
641 Decode a mime encoded http message body with multipart/form-data Content-Type.
643 Stores all extracted data associated with its parameter name
644 in the params table within the given message object. Multiple parameter
645 values are stored as tables, ordinary ones as strings.
647 If an optional file callback function is given then it is feeded with the
648 file contents chunk by chunk and only the extracted file name is stored
649 within the params table. The callback function will be called subsequently
650 with three arguments:
651 o Table containing decoded (name, file) and raw (headers) mime header data
652 o String value containing a chunk of the file data
653 o Boolean which indicates wheather the current chunk is the last one (eof)
661 src: Ltn12 source function
665 msg: HTTP message object
669 filecb: File callback function (optional)
679 <h3>Return values:</h3>
682 <li>Value indicating successful operation (not nil means "ok")
684 <li>String containing the error if unsuccessful
704 <dt><a name="parse_message_body"></a><strong>parse_message_body</strong> (src, msg, filecb)</dt>
708 Try to extract and decode a http message body from the given ltn12 source.
709 This function will examine the Content-Type within the given message object
710 to select the appropriate content decoder.
712 Currently the application/x-www-urlencoded and application/form-data
713 mime types are supported. If the encountered content encoding can't be
714 handled then the whole message body will be stored unaltered as "content"
715 property within the given message object.
723 src: Ltn12 source function
727 msg: HTTP message object
731 filecb: File data callback (optional, see mimedecode_message_body())
741 <h3>Return values:</h3>
744 <li>Value indicating successful operation (not nil means "ok")
746 <li>String containing the error if unsuccessful
766 <dt><a name="prepare_content"></a><strong>prepare_content</strong> (mime)</dt>
770 Set the mime type of following content data.
778 mime: Mimetype of following content
795 <dt><a name="redirect"></a><strong>redirect</strong> (url)</dt>
799 Redirects the client to a new URL and closes the connection.
824 <dt><a name="setfilehandler"></a><strong>setfilehandler</strong> (callback)</dt>
828 Set a handler function for incoming user file uploads.
836 callback: Handler function
853 <dt><a name="source"></a><strong>source</strong> ()</dt>
857 Get the RAW HTTP input source
866 <h3>Return value:</h3>
876 <dt><a name="splice"></a><strong>splice</strong> (fp, size)</dt>
880 Splice data from a filedescriptor to the client.
892 size: Bytes to splice (optional)
909 <dt><a name="status"></a><strong>status</strong> (code, message)</dt>
913 Set the HTTP status code and status message.
925 message: Status message
942 <dt><a name="urldecode"></a><strong>urldecode</strong> (str, no_plus)</dt>
946 Return the URL-decoded equivalent of a string.
954 str: URL-encoded string
958 no_plus: Don't decode + to " "
968 <h3>Return value:</h3>
976 <li><a href="#urlencode">
987 <dt><a name="urldecode_message_body"></a><strong>urldecode_message_body</strong> (src, msg)</dt>
991 Decode an urlencoded http message body with application/x-www-urlencoded
994 Stores all extracted data associated with its parameter name in the params
995 table within the given message object. Multiple parameter values are stored
996 as tables, ordinary ones as strings.
1004 src: Ltn12 source function
1008 msg: HTTP message object
1018 <h3>Return values:</h3>
1021 <li>Value indicating successful operation (not nil means "ok")
1023 <li>String containing the error if unsuccessful
1033 parse_message_header
1043 <dt><a name="urldecode_params"></a><strong>urldecode_params</strong> (url, tbl)</dt>
1047 Extract and split urlencoded data pairs, separated bei either "&" or ";"
1048 from given url or string. Returns a table with urldecoded values.
1050 Simple parameters are stored as string values associated with the parameter
1051 name within the table. Parameters with multiple values are stored as array
1052 containing the corresponding values.
1060 url: The url or string which contains x-www-urlencoded form data
1064 tbl: Use the given table for storing values (optional)
1074 <h3>Return value:</h3>
1075 Table containing the urldecoded parameters
1082 <li><a href="#urlencode_params">
1093 <dt><a name="urlencode"></a><strong>urlencode</strong> (str)</dt>
1097 Return the URL-encoded equivalent of a string.
1115 <h3>Return value:</h3>
1123 <li><a href="#urldecode">
1134 <dt><a name="urlencode_params"></a><strong>urlencode_params</strong> (tbl)</dt>
1138 Encode each key-value-pair in given table to x-www-urlencoded format,
1141 Tables are encoded as parameters with multiple values by repeating the
1142 parameter name with each value.
1150 tbl: Table with the values
1160 <h3>Return value:</h3>
1161 String containing encoded values
1168 <li><a href="#urldecode_params">
1179 <dt><a name="write"></a><strong>write</strong> (content, src_err)</dt>
1183 Send a chunk of content data to the client.
1185 This function is as a valid LTN12 sink.
1186 If the content chunk is nil this function will automatically invoke close.
1194 content: Content chunk
1198 src_err: Error object from source (optional)
1213 <li><a href="#close">
1224 <dt><a name="write_json"></a><strong>write_json</strong> (data)</dt>
1228 Send the given data as JSON encoded string.
1257 </div> <!-- id="content" -->
1259 </div> <!-- id="main" -->
1262 <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
1263 </div> <!-- id="about" -->
1265 </div> <!-- id="container" -->