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.protocol</strong></li>
44 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
48 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
52 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.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.jsonc.html">luci.jsonc</a>
72 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
76 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
80 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
84 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
88 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
92 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
96 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
100 <a href="../modules/nixio.html">nixio</a>
104 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
108 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
112 <a href="../modules/nixio.File.html">nixio.File</a>
116 <a href="../modules/nixio.README.html">nixio.README</a>
120 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
124 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
128 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
132 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
136 <a href="../modules/nixio.bin.html">nixio.bin</a>
140 <a href="../modules/nixio.bit.html">nixio.bit</a>
144 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
148 <a href="../modules/nixio.fs.html">nixio.fs</a>
163 </div><!-- id="navigation" -->
167 <h1>Class <code>luci.http.protocol</code></h1>
178 <table class="function_list">
181 <td class="name" nowrap><a href="#header_source">header_source</a> (sock)</td>
184 Creates a ltn12 source from the given socket.</td>
188 <td class="name" nowrap><a href="#mimedecode_message_body">mimedecode_message_body</a> (src, msg, filecb)</td>
191 Decode a mime encoded http message body with multipart/form-data
197 <td class="name" nowrap><a href="#parse_message_body">parse_message_body</a> (src, msg, filecb)</td>
200 Try to extract and decode a http message body from the given ltn12 source.</td>
204 <td class="name" nowrap><a href="#parse_message_header">parse_message_header</a> (src)</td>
207 Try to extract an http message header including information like protocol
209 version, message headers and resulting CGI environment variables from the
210 given ltn12 source.</td>
214 <td class="name" nowrap><a href="#urldecode">urldecode</a> (str, no_plus)</td>
217 Decode an urlencoded string - optionally without decoding
219 the "+" sign to " " - and return the decoded string.</td>
223 <td class="name" nowrap><a href="#urldecode_message_body">urldecode_message_body</a> (src, msg)</td>
226 Decode an urlencoded http message body with application/x-www-urlencoded
232 <td class="name" nowrap><a href="#urldecode_params">urldecode_params</a> (url, tbl)</td>
235 Extract and split urlencoded data pairs, separated bei either "&" or ";"
237 from given url or string.</td>
241 <td class="name" nowrap><a href="#urlencode">urlencode</a> (str)</td>
244 Encode given string to x-www-urlencoded format.</td>
248 <td class="name" nowrap><a href="#urlencode_params">urlencode_params</a> (tbl)</td>
251 Encode each key-value-pair in given table to x-www-urlencoded format,
253 separated by "&".</td>
267 <h2><a name="functions"></a>Functions</h2>
268 <dl class="function">
272 <dt><a name="header_source"></a><strong>header_source</strong> (sock)</dt>
276 Creates a ltn12 source from the given socket. The source will return it's
278 data line by line with the trailing \r\n stripped of.
285 sock: Readable network socket
295 <h3>Return value:</h3>
296 Ltn12 source function
305 <dt><a name="mimedecode_message_body"></a><strong>mimedecode_message_body</strong> (src, msg, filecb)</dt>
309 Decode a mime encoded http message body with multipart/form-data
311 Content-Type. Stores all extracted data associated with its parameter name
312 in the params table withing the given message object. Multiple parameter
313 values are stored as tables, ordinary ones as strings.
314 If an optional file callback function is given then it is feeded with the
315 file contents chunk by chunk and only the extracted file name is stored
316 within the params table. The callback function will be called subsequently
317 with three arguments:
318 o Table containing decoded (name, file) and raw (headers) mime header data
319 o String value containing a chunk of the file data
320 o Boolean which indicates wheather the current chunk is the last one (eof)
327 src: Ltn12 source function
331 msg: HTTP message object
335 filecb: File callback function (optional)
345 <h3>Return values:</h3>
348 <li>Value indicating successful operation (not nil means "ok")
350 <li>String containing the error if unsuccessful
359 <li><a href="#parse_message_header">
370 <dt><a name="parse_message_body"></a><strong>parse_message_body</strong> (src, msg, filecb)</dt>
374 Try to extract and decode a http message body from the given ltn12 source.
376 This function will examine the Content-Type within the given message object
377 to select the appropriate content decoder.
378 Currently the application/x-www-urlencoded and application/form-data
379 mime types are supported. If the encountered content encoding can't be
380 handled then the whole message body will be stored unaltered as "content"
381 property within the given message object.
388 src: Ltn12 source function
392 msg: HTTP message object
396 filecb: File data callback (optional, see mimedecode_message_body())
406 <h3>Return values:</h3>
409 <li>Value indicating successful operation (not nil means "ok")
411 <li>String containing the error if unsuccessful
420 <li><a href="#parse_message_header">
431 <dt><a name="parse_message_header"></a><strong>parse_message_header</strong> (src)</dt>
435 Try to extract an http message header including information like protocol
437 version, message headers and resulting CGI environment variables from the
445 src: Ltn12 source function
455 <h3>Return value:</h3>
463 <li><a href="#parse_message_body">
474 <dt><a name="urldecode"></a><strong>urldecode</strong> (str, no_plus)</dt>
478 Decode an urlencoded string - optionally without decoding
480 the "+" sign to " " - and return the decoded string.
487 str: Input string in x-www-urlencoded format
491 no_plus: Don't decode "+" signs to spaces
501 <h3>Return value:</h3>
509 <li><a href="#urlencode">
520 <dt><a name="urldecode_message_body"></a><strong>urldecode_message_body</strong> (src, msg)</dt>
524 Decode an urlencoded http message body with application/x-www-urlencoded
526 Content-Type. Stores all extracted data associated with its parameter name
527 in the params table withing the given message object. Multiple parameter
528 values are stored as tables, ordinary ones as strings.
535 src: Ltn12 source function
539 msg: HTTP message object
549 <h3>Return values:</h3>
552 <li>Value indicating successful operation (not nil means "ok")
554 <li>String containing the error if unsuccessful
563 <li><a href="#parse_message_header">
574 <dt><a name="urldecode_params"></a><strong>urldecode_params</strong> (url, tbl)</dt>
578 Extract and split urlencoded data pairs, separated bei either "&" or ";"
580 from given url or string. Returns a table with urldecoded values.
581 Simple parameters are stored as string values associated with the parameter
582 name within the table. Parameters with multiple values are stored as array
583 containing the corresponding values.
590 url: The url or string which contains x-www-urlencoded form data
594 tbl: Use the given table for storing values (optional)
604 <h3>Return value:</h3>
605 Table containing the urldecoded parameters
612 <li><a href="#urlencode_params">
623 <dt><a name="urlencode"></a><strong>urlencode</strong> (str)</dt>
627 Encode given string to x-www-urlencoded format.
635 str: String to encode
645 <h3>Return value:</h3>
646 String containing the encoded data
653 <li><a href="#urldecode">
664 <dt><a name="urlencode_params"></a><strong>urlencode_params</strong> (tbl)</dt>
668 Encode each key-value-pair in given table to x-www-urlencoded format,
670 separated by "&". Tables are encoded as parameters with multiple values by
671 repeating the parameter name with each value.
678 tbl: Table with the values
688 <h3>Return value:</h3>
689 String containing encoded values
696 <li><a href="#urldecode_params">
711 </div> <!-- id="content" -->
713 </div> <!-- id="main" -->
716 <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>
717 </div> <!-- id="about" -->
719 </div> <!-- id="container" -->