Merge pull request #478 from LuttyYang/master
[project/luci.git] / documentation / api / modules / luci.http.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html>
4 <head>
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"/-->
8 </head>
9
10 <body>
11 <div id="container">
12
13 <div id="product">
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" -->
18
19 <div id="main">
20
21 <div id="navigation">
22
23
24 <h1>LuaDoc</h1>
25 <ul>
26         
27         <li><a href="../index.html">Index</a></li>
28         
29 </ul>
30
31
32 <!-- Module list -->
33
34 <h1>Modules</h1>
35 <ul>
36
37         <li>
38                 <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
39         </li>
40
41         <li><strong>luci.http</strong></li>
42         
43         <li>
44                 <a href="../modules/luci.http.protocol.html">luci.http.protocol</a>
45         </li>
46
47         <li>
48                 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
49         </li>
50
51         <li>
52                 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
53         </li>
54
55         <li>
56                 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
57         </li>
58
59         <li>
60                 <a href="../modules/luci.i18n.html">luci.i18n</a>
61         </li>
62
63         <li>
64                 <a href="../modules/luci.ip.html">luci.ip</a>
65         </li>
66
67         <li>
68                 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
69         </li>
70
71         <li>
72                 <a href="../modules/luci.json.html">luci.json</a>
73         </li>
74
75         <li>
76                 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
77         </li>
78
79         <li>
80                 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
81         </li>
82
83         <li>
84                 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
85         </li>
86
87         <li>
88                 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
89         </li>
90
91         <li>
92                 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
93         </li>
94
95         <li>
96                 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
97         </li>
98
99         <li>
100                 <a href="../modules/luci.sys.html">luci.sys</a>
101         </li>
102
103         <li>
104                 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
105         </li>
106
107         <li>
108                 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
109         </li>
110
111         <li>
112                 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
113         </li>
114
115         <li>
116                 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
117         </li>
118
119         <li>
120                 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
121         </li>
122
123         <li>
124                 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
125         </li>
126
127         <li>
128                 <a href="../modules/luci.util.html">luci.util</a>
129         </li>
130
131         <li>
132                 <a href="../modules/nixio.html">nixio</a>
133         </li>
134
135         <li>
136                 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
137         </li>
138
139         <li>
140                 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
141         </li>
142
143         <li>
144                 <a href="../modules/nixio.File.html">nixio.File</a>
145         </li>
146
147         <li>
148                 <a href="../modules/nixio.README.html">nixio.README</a>
149         </li>
150
151         <li>
152                 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
153         </li>
154
155         <li>
156                 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
157         </li>
158
159         <li>
160                 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
161         </li>
162
163         <li>
164                 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
165         </li>
166
167         <li>
168                 <a href="../modules/nixio.bin.html">nixio.bin</a>
169         </li>
170
171         <li>
172                 <a href="../modules/nixio.bit.html">nixio.bit</a>
173         </li>
174
175         <li>
176                 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
177         </li>
178
179         <li>
180                 <a href="../modules/nixio.fs.html">nixio.fs</a>
181         </li>
182
183 </ul>
184
185
186
187 <!-- File list -->
188
189
190
191
192
193
194
195 </div><!-- id="navigation" -->
196
197 <div id="content">
198
199 <h1>Class <code>luci.http</code></h1>
200
201 <p></p>
202
203
204
205
206
207
208
209 <h2>Functions</h2>
210 <table class="function_list">
211
212         <tr>
213         <td class="name" nowrap><a href="#build_querystring">build_querystring</a>&nbsp;(table)</td>
214         <td class="summary">
215  
216 Create a querystring out of a table of key - value pairs.</td>
217         </tr>
218
219         <tr>
220         <td class="name" nowrap><a href="#close">close</a>&nbsp;()</td>
221         <td class="summary">
222  
223 Close the HTTP-Connection.</td>
224         </tr>
225
226         <tr>
227         <td class="name" nowrap><a href="#content">content</a>&nbsp;()</td>
228         <td class="summary">
229  
230 Return the request content if the request was of unknown type.</td>
231         </tr>
232
233         <tr>
234         <td class="name" nowrap><a href="#formvalue">formvalue</a>&nbsp;(name, noparse)</td>
235         <td class="summary">
236  
237 Get a certain HTTP input value or a table of all input values.</td>
238         </tr>
239
240         <tr>
241         <td class="name" nowrap><a href="#formvaluetable">formvaluetable</a>&nbsp;(prefix)</td>
242         <td class="summary">
243  
244 Get a table of all HTTP input values with a certain prefix.</td>
245         </tr>
246
247         <tr>
248         <td class="name" nowrap><a href="#getcookie">getcookie</a>&nbsp;(name)</td>
249         <td class="summary">
250  
251 Get the value of a certain HTTP-Cookie.</td>
252         </tr>
253
254         <tr>
255         <td class="name" nowrap><a href="#getenv">getenv</a>&nbsp;(name)</td>
256         <td class="summary">
257  
258 Get the value of a certain HTTP environment variable 
259  
260 or the environment table itself.</td>
261         </tr>
262
263         <tr>
264         <td class="name" nowrap><a href="#header">header</a>&nbsp;(key, value)</td>
265         <td class="summary">
266  
267 Send a HTTP-Header.</td>
268         </tr>
269
270         <tr>
271         <td class="name" nowrap><a href="#prepare_content">prepare_content</a>&nbsp;(mime)</td>
272         <td class="summary">
273  
274 Set the mime type of following content data.</td>
275         </tr>
276
277         <tr>
278         <td class="name" nowrap><a href="#redirect">redirect</a>&nbsp;(url)</td>
279         <td class="summary">
280  
281 Redirects the client to a new URL and closes the connection.</td>
282         </tr>
283
284         <tr>
285         <td class="name" nowrap><a href="#setfilehandler">setfilehandler</a>&nbsp;(callback)</td>
286         <td class="summary">
287  
288 Set a handler function for incoming user file uploads.</td>
289         </tr>
290
291         <tr>
292         <td class="name" nowrap><a href="#source">source</a>&nbsp;()</td>
293         <td class="summary">
294  
295 Get the RAW HTTP input source 
296  </td>
297         </tr>
298
299         <tr>
300         <td class="name" nowrap><a href="#splice">splice</a>&nbsp;(fp, size)</td>
301         <td class="summary">
302  
303 Splice data from a filedescriptor to the client.</td>
304         </tr>
305
306         <tr>
307         <td class="name" nowrap><a href="#status">status</a>&nbsp;(code, message)</td>
308         <td class="summary">
309  
310 Set the HTTP status code and status message.</td>
311         </tr>
312
313         <tr>
314         <td class="name" nowrap><a href="#write">write</a>&nbsp;(content, src_err)</td>
315         <td class="summary">
316  
317 Send a chunk of content data to the client.</td>
318         </tr>
319
320         <tr>
321         <td class="name" nowrap><a href="#write_json">write_json</a>&nbsp;(data)</td>
322         <td class="summary">
323  
324 Send the given data as JSON encoded string.</td>
325         </tr>
326
327 </table>
328
329
330
331
332
333
334 <br/>
335 <br/>
336
337
338 <h2><a name="functions"></a>Functions</h2>
339 <dl class="function">
340
341
342
343 <dt><a name="build_querystring"></a><strong>build_querystring</strong>&nbsp;(table)</dt>
344 <dd>
345
346  
347 Create a querystring out of a table of key - value pairs. 
348
349
350
351 <h3>Parameters</h3>
352 <ul>
353         
354         <li>
355           table: Query string source table
356         </li>
357         
358 </ul>
359
360
361
362
363
364
365 <h3>Return value:</h3>
366 Encoded HTTP query string
367
368
369
370 </dd>
371
372
373
374
375 <dt><a name="close"></a><strong>close</strong>&nbsp;()</dt>
376 <dd>
377
378  
379 Close the HTTP-Connection. 
380  
381
382
383
384
385
386
387
388
389
390
391 </dd>
392
393
394
395
396 <dt><a name="content"></a><strong>content</strong>&nbsp;()</dt>
397 <dd>
398
399  
400 Return the request content if the request was of unknown type. 
401
402
403
404
405
406
407
408
409 <h3>Return values:</h3>
410 <ol>
411         
412         <li>HTTP request body
413         
414         <li>HTTP request body length
415         
416 </ol>
417
418
419
420 </dd>
421
422
423
424
425 <dt><a name="formvalue"></a><strong>formvalue</strong>&nbsp;(name, noparse)</dt>
426 <dd>
427
428  
429 Get a certain HTTP input value or a table of all input values. 
430
431
432
433 <h3>Parameters</h3>
434 <ul>
435         
436         <li>
437           name: Name of the GET or POST variable to fetch
438         </li>
439         
440         <li>
441           noparse: Don't parse POST data before getting the value
442         </li>
443         
444 </ul>
445
446
447
448
449
450
451 <h3>Return value:</h3>
452 HTTP input value or table of all input value
453
454
455
456 </dd>
457
458
459
460
461 <dt><a name="formvaluetable"></a><strong>formvaluetable</strong>&nbsp;(prefix)</dt>
462 <dd>
463
464  
465 Get a table of all HTTP input values with a certain prefix. 
466
467
468
469 <h3>Parameters</h3>
470 <ul>
471         
472         <li>
473           prefix: Prefix
474         </li>
475         
476 </ul>
477
478
479
480
481
482
483 <h3>Return value:</h3>
484 Table of all HTTP input values with given prefix
485
486
487
488 </dd>
489
490
491
492
493 <dt><a name="getcookie"></a><strong>getcookie</strong>&nbsp;(name)</dt>
494 <dd>
495
496  
497 Get the value of a certain HTTP-Cookie. 
498
499
500
501 <h3>Parameters</h3>
502 <ul>
503         
504         <li>
505           name: Cookie Name
506         </li>
507         
508 </ul>
509
510
511
512
513
514
515 <h3>Return value:</h3>
516 String containing cookie data
517
518
519
520 </dd>
521
522
523
524
525 <dt><a name="getenv"></a><strong>getenv</strong>&nbsp;(name)</dt>
526 <dd>
527
528  
529 Get the value of a certain HTTP environment variable 
530  
531 or the environment table itself.
532
533
534 <h3>Parameters</h3>
535 <ul>
536         
537         <li>
538           name: Environment variable
539         </li>
540         
541 </ul>
542
543
544
545
546
547
548 <h3>Return value:</h3>
549 HTTP environment value or environment table
550
551
552
553 </dd>
554
555
556
557
558 <dt><a name="header"></a><strong>header</strong>&nbsp;(key, value)</dt>
559 <dd>
560
561  
562 Send a HTTP-Header. 
563
564
565
566 <h3>Parameters</h3>
567 <ul>
568         
569         <li>
570           key: Header key
571         </li>
572         
573         <li>
574           value: Header value
575         </li>
576         
577 </ul>
578
579
580
581
582
583
584
585
586 </dd>
587
588
589
590
591 <dt><a name="prepare_content"></a><strong>prepare_content</strong>&nbsp;(mime)</dt>
592 <dd>
593
594  
595 Set the mime type of following content data. 
596
597
598
599 <h3>Parameters</h3>
600 <ul>
601         
602         <li>
603           mime: Mimetype of following content
604         </li>
605         
606 </ul>
607
608
609
610
611
612
613
614
615 </dd>
616
617
618
619
620 <dt><a name="redirect"></a><strong>redirect</strong>&nbsp;(url)</dt>
621 <dd>
622
623  
624 Redirects the client to a new URL and closes the connection. 
625
626
627
628 <h3>Parameters</h3>
629 <ul>
630         
631         <li>
632           url: Target URL
633         </li>
634         
635 </ul>
636
637
638
639
640
641
642
643
644 </dd>
645
646
647
648
649 <dt><a name="setfilehandler"></a><strong>setfilehandler</strong>&nbsp;(callback)</dt>
650 <dd>
651
652  
653 Set a handler function for incoming user file uploads. 
654
655
656
657 <h3>Parameters</h3>
658 <ul>
659         
660         <li>
661           callback: Handler function
662         </li>
663         
664 </ul>
665
666
667
668
669
670
671
672
673 </dd>
674
675
676
677
678 <dt><a name="source"></a><strong>source</strong>&nbsp;()</dt>
679 <dd>
680
681  
682 Get the RAW HTTP input source 
683
684
685
686
687
688
689
690
691 <h3>Return value:</h3>
692 HTTP LTN12 source
693
694
695
696 </dd>
697
698
699
700
701 <dt><a name="splice"></a><strong>splice</strong>&nbsp;(fp, size)</dt>
702 <dd>
703
704  
705 Splice data from a filedescriptor to the client. 
706
707
708
709 <h3>Parameters</h3>
710 <ul>
711         
712         <li>
713           fp: File descriptor
714         </li>
715         
716         <li>
717           size: Bytes to splice (optional)
718         </li>
719         
720 </ul>
721
722
723
724
725
726
727
728
729 </dd>
730
731
732
733
734 <dt><a name="status"></a><strong>status</strong>&nbsp;(code, message)</dt>
735 <dd>
736
737  
738 Set the HTTP status code and status message. 
739
740
741
742 <h3>Parameters</h3>
743 <ul>
744         
745         <li>
746           code: Status code
747         </li>
748         
749         <li>
750           message: Status message
751         </li>
752         
753 </ul>
754
755
756
757
758
759
760
761
762 </dd>
763
764
765
766
767 <dt><a name="write"></a><strong>write</strong>&nbsp;(content, src_err)</dt>
768 <dd>
769
770  
771 Send a chunk of content data to the client. 
772  
773 This function is as a valid LTN12 sink. 
774 If the content chunk is nil this function will automatically invoke close.
775
776
777 <h3>Parameters</h3>
778 <ul>
779         
780         <li>
781           content: Content chunk
782         </li>
783         
784         <li>
785           src_err: Error object from source (optional)
786         </li>
787         
788 </ul>
789
790
791
792
793
794
795
796
797 <h3>See also:</h3>
798 <ul>
799         
800         <li><a href="#close">
801                 close
802         </a>
803         
804 </ul>
805
806 </dd>
807
808
809
810
811 <dt><a name="write_json"></a><strong>write_json</strong>&nbsp;(data)</dt>
812 <dd>
813
814  
815 Send the given data as JSON encoded string. 
816
817
818
819 <h3>Parameters</h3>
820 <ul>
821         
822         <li>
823           data: Data to send
824         </li>
825         
826 </ul>
827
828
829
830
831
832
833
834
835 </dd>
836
837
838 </dl>
839
840
841
842
843
844 </div> <!-- id="content" -->
845
846 </div> <!-- id="main" -->
847
848 <div id="about">
849         <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>
850 </div> <!-- id="about" -->
851
852 </div> <!-- id="container" -->
853 </body>
854 </html>