luci.http.protocol.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <div id="navigation">
  18. <h1>LuaDoc</h1>
  19. <ul>
  20. <li><a href="../index.html">Index</a></li>
  21. </ul>
  22. <!-- Module list -->
  23. <h1>Modules</h1>
  24. <ul>
  25. <li>
  26. <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
  27. </li>
  28. <li>
  29. <a href="../modules/luci.http.html">luci.http</a>
  30. </li>
  31. <li><strong>luci.http.protocol</strong></li>
  32. <li>
  33. <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
  34. </li>
  35. <li>
  36. <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
  37. </li>
  38. <li>
  39. <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
  40. </li>
  41. <li>
  42. <a href="../modules/luci.i18n.html">luci.i18n</a>
  43. </li>
  44. <li>
  45. <a href="../modules/luci.ip.html">luci.ip</a>
  46. </li>
  47. <li>
  48. <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
  49. </li>
  50. <li>
  51. <a href="../modules/luci.json.html">luci.json</a>
  52. </li>
  53. <li>
  54. <a href="../modules/luci.jsonc.html">luci.jsonc</a>
  55. </li>
  56. <li>
  57. <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
  58. </li>
  59. <li>
  60. <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
  61. </li>
  62. <li>
  63. <a href="../modules/luci.model.uci.html">luci.model.uci</a>
  64. </li>
  65. <li>
  66. <a href="../modules/luci.rpcc.html">luci.rpcc</a>
  67. </li>
  68. <li>
  69. <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
  70. </li>
  71. <li>
  72. <a href="../modules/luci.sys.html">luci.sys</a>
  73. </li>
  74. <li>
  75. <a href="../modules/luci.sys.init.html">luci.sys.init</a>
  76. </li>
  77. <li>
  78. <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
  79. </li>
  80. <li>
  81. <a href="../modules/luci.sys.net.html">luci.sys.net</a>
  82. </li>
  83. <li>
  84. <a href="../modules/luci.sys.process.html">luci.sys.process</a>
  85. </li>
  86. <li>
  87. <a href="../modules/luci.sys.user.html">luci.sys.user</a>
  88. </li>
  89. <li>
  90. <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
  91. </li>
  92. <li>
  93. <a href="../modules/luci.util.html">luci.util</a>
  94. </li>
  95. <li>
  96. <a href="../modules/nixio.html">nixio</a>
  97. </li>
  98. <li>
  99. <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
  100. </li>
  101. <li>
  102. <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
  103. </li>
  104. <li>
  105. <a href="../modules/nixio.File.html">nixio.File</a>
  106. </li>
  107. <li>
  108. <a href="../modules/nixio.README.html">nixio.README</a>
  109. </li>
  110. <li>
  111. <a href="../modules/nixio.Socket.html">nixio.Socket</a>
  112. </li>
  113. <li>
  114. <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
  115. </li>
  116. <li>
  117. <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
  118. </li>
  119. <li>
  120. <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
  121. </li>
  122. <li>
  123. <a href="../modules/nixio.bin.html">nixio.bin</a>
  124. </li>
  125. <li>
  126. <a href="../modules/nixio.bit.html">nixio.bit</a>
  127. </li>
  128. <li>
  129. <a href="../modules/nixio.crypto.html">nixio.crypto</a>
  130. </li>
  131. <li>
  132. <a href="../modules/nixio.fs.html">nixio.fs</a>
  133. </li>
  134. </ul>
  135. <!-- File list -->
  136. </div><!-- id="navigation" -->
  137. <div id="content">
  138. <h1>Class <code>luci.http.protocol</code></h1>
  139. <p></p>
  140. <h2>Functions</h2>
  141. <table class="function_list">
  142. <tr>
  143. <td class="name" nowrap><a href="#header_source">header_source</a>&nbsp;(sock)</td>
  144. <td class="summary">
  145. Creates a ltn12 source from the given socket.</td>
  146. </tr>
  147. <tr>
  148. <td class="name" nowrap><a href="#mimedecode_message_body">mimedecode_message_body</a>&nbsp;(src, msg, filecb)</td>
  149. <td class="summary">
  150. Decode a mime encoded http message body with multipart/form-data
  151. Content-Type.</td>
  152. </tr>
  153. <tr>
  154. <td class="name" nowrap><a href="#parse_message_body">parse_message_body</a>&nbsp;(src, msg, filecb)</td>
  155. <td class="summary">
  156. Try to extract and decode a http message body from the given ltn12 source.</td>
  157. </tr>
  158. <tr>
  159. <td class="name" nowrap><a href="#parse_message_header">parse_message_header</a>&nbsp;(src)</td>
  160. <td class="summary">
  161. Try to extract an http message header including information like protocol
  162. version, message headers and resulting CGI environment variables from the
  163. given ltn12 source.</td>
  164. </tr>
  165. <tr>
  166. <td class="name" nowrap><a href="#urldecode">urldecode</a>&nbsp;(str, no_plus)</td>
  167. <td class="summary">
  168. Decode an urlencoded string - optionally without decoding
  169. the "+" sign to " " - and return the decoded string.</td>
  170. </tr>
  171. <tr>
  172. <td class="name" nowrap><a href="#urldecode_message_body">urldecode_message_body</a>&nbsp;(src, msg)</td>
  173. <td class="summary">
  174. Decode an urlencoded http message body with application/x-www-urlencoded
  175. Content-Type.</td>
  176. </tr>
  177. <tr>
  178. <td class="name" nowrap><a href="#urldecode_params">urldecode_params</a>&nbsp;(url, tbl)</td>
  179. <td class="summary">
  180. Extract and split urlencoded data pairs, separated bei either "&" or ";"
  181. from given url or string.</td>
  182. </tr>
  183. <tr>
  184. <td class="name" nowrap><a href="#urlencode">urlencode</a>&nbsp;(str)</td>
  185. <td class="summary">
  186. Encode given string to x-www-urlencoded format.</td>
  187. </tr>
  188. <tr>
  189. <td class="name" nowrap><a href="#urlencode_params">urlencode_params</a>&nbsp;(tbl)</td>
  190. <td class="summary">
  191. Encode each key-value-pair in given table to x-www-urlencoded format,
  192. separated by "&".</td>
  193. </tr>
  194. </table>
  195. <br/>
  196. <br/>
  197. <h2><a name="functions"></a>Functions</h2>
  198. <dl class="function">
  199. <dt><a name="header_source"></a><strong>header_source</strong>&nbsp;(sock)</dt>
  200. <dd>
  201. Creates a ltn12 source from the given socket. The source will return it's
  202. data line by line with the trailing \r\n stripped of.
  203. <h3>Parameters</h3>
  204. <ul>
  205. <li>
  206. sock: Readable network socket
  207. </li>
  208. </ul>
  209. <h3>Return value:</h3>
  210. Ltn12 source function
  211. </dd>
  212. <dt><a name="mimedecode_message_body"></a><strong>mimedecode_message_body</strong>&nbsp;(src, msg, filecb)</dt>
  213. <dd>
  214. Decode a mime encoded http message body with multipart/form-data
  215. Content-Type. Stores all extracted data associated with its parameter name
  216. in the params table within the given message object. Multiple parameter
  217. values are stored as tables, ordinary ones as strings.
  218. If an optional file callback function is given then it is feeded with the
  219. file contents chunk by chunk and only the extracted file name is stored
  220. within the params table. The callback function will be called subsequently
  221. with three arguments:
  222. o Table containing decoded (name, file) and raw (headers) mime header data
  223. o String value containing a chunk of the file data
  224. o Boolean which indicates wheather the current chunk is the last one (eof)
  225. <h3>Parameters</h3>
  226. <ul>
  227. <li>
  228. src: Ltn12 source function
  229. </li>
  230. <li>
  231. msg: HTTP message object
  232. </li>
  233. <li>
  234. filecb: File callback function (optional)
  235. </li>
  236. </ul>
  237. <h3>Return values:</h3>
  238. <ol>
  239. <li>Value indicating successful operation (not nil means "ok")
  240. <li>String containing the error if unsuccessful
  241. </ol>
  242. <h3>See also:</h3>
  243. <ul>
  244. <li><a href="#parse_message_header">
  245. parse_message_header
  246. </a>
  247. </ul>
  248. </dd>
  249. <dt><a name="parse_message_body"></a><strong>parse_message_body</strong>&nbsp;(src, msg, filecb)</dt>
  250. <dd>
  251. Try to extract and decode a http message body from the given ltn12 source.
  252. This function will examine the Content-Type within the given message object
  253. to select the appropriate content decoder.
  254. Currently the application/x-www-urlencoded and application/form-data
  255. mime types are supported. If the encountered content encoding can't be
  256. handled then the whole message body will be stored unaltered as "content"
  257. property within the given message object.
  258. <h3>Parameters</h3>
  259. <ul>
  260. <li>
  261. src: Ltn12 source function
  262. </li>
  263. <li>
  264. msg: HTTP message object
  265. </li>
  266. <li>
  267. filecb: File data callback (optional, see mimedecode_message_body())
  268. </li>
  269. </ul>
  270. <h3>Return values:</h3>
  271. <ol>
  272. <li>Value indicating successful operation (not nil means "ok")
  273. <li>String containing the error if unsuccessful
  274. </ol>
  275. <h3>See also:</h3>
  276. <ul>
  277. <li><a href="#parse_message_header">
  278. parse_message_header
  279. </a>
  280. </ul>
  281. </dd>
  282. <dt><a name="parse_message_header"></a><strong>parse_message_header</strong>&nbsp;(src)</dt>
  283. <dd>
  284. Try to extract an http message header including information like protocol
  285. version, message headers and resulting CGI environment variables from the
  286. given ltn12 source.
  287. <h3>Parameters</h3>
  288. <ul>
  289. <li>
  290. src: Ltn12 source function
  291. </li>
  292. </ul>
  293. <h3>Return value:</h3>
  294. HTTP message object
  295. <h3>See also:</h3>
  296. <ul>
  297. <li><a href="#parse_message_body">
  298. parse_message_body
  299. </a>
  300. </ul>
  301. </dd>
  302. <dt><a name="urldecode"></a><strong>urldecode</strong>&nbsp;(str, no_plus)</dt>
  303. <dd>
  304. Decode an urlencoded string - optionally without decoding
  305. the "+" sign to " " - and return the decoded string.
  306. <h3>Parameters</h3>
  307. <ul>
  308. <li>
  309. str: Input string in x-www-urlencoded format
  310. </li>
  311. <li>
  312. no_plus: Don't decode "+" signs to spaces
  313. </li>
  314. </ul>
  315. <h3>Return value:</h3>
  316. The decoded string
  317. <h3>See also:</h3>
  318. <ul>
  319. <li><a href="#urlencode">
  320. urlencode
  321. </a>
  322. </ul>
  323. </dd>
  324. <dt><a name="urldecode_message_body"></a><strong>urldecode_message_body</strong>&nbsp;(src, msg)</dt>
  325. <dd>
  326. Decode an urlencoded http message body with application/x-www-urlencoded
  327. Content-Type. Stores all extracted data associated with its parameter name
  328. in the params table within the given message object. Multiple parameter
  329. values are stored as tables, ordinary ones as strings.
  330. <h3>Parameters</h3>
  331. <ul>
  332. <li>
  333. src: Ltn12 source function
  334. </li>
  335. <li>
  336. msg: HTTP message object
  337. </li>
  338. </ul>
  339. <h3>Return values:</h3>
  340. <ol>
  341. <li>Value indicating successful operation (not nil means "ok")
  342. <li>String containing the error if unsuccessful
  343. </ol>
  344. <h3>See also:</h3>
  345. <ul>
  346. <li><a href="#parse_message_header">
  347. parse_message_header
  348. </a>
  349. </ul>
  350. </dd>
  351. <dt><a name="urldecode_params"></a><strong>urldecode_params</strong>&nbsp;(url, tbl)</dt>
  352. <dd>
  353. Extract and split urlencoded data pairs, separated bei either "&" or ";"
  354. from given url or string. Returns a table with urldecoded values.
  355. Simple parameters are stored as string values associated with the parameter
  356. name within the table. Parameters with multiple values are stored as array
  357. containing the corresponding values.
  358. <h3>Parameters</h3>
  359. <ul>
  360. <li>
  361. url: The url or string which contains x-www-urlencoded form data
  362. </li>
  363. <li>
  364. tbl: Use the given table for storing values (optional)
  365. </li>
  366. </ul>
  367. <h3>Return value:</h3>
  368. Table containing the urldecoded parameters
  369. <h3>See also:</h3>
  370. <ul>
  371. <li><a href="#urlencode_params">
  372. urlencode_params
  373. </a>
  374. </ul>
  375. </dd>
  376. <dt><a name="urlencode"></a><strong>urlencode</strong>&nbsp;(str)</dt>
  377. <dd>
  378. Encode given string to x-www-urlencoded format.
  379. <h3>Parameters</h3>
  380. <ul>
  381. <li>
  382. str: String to encode
  383. </li>
  384. </ul>
  385. <h3>Return value:</h3>
  386. String containing the encoded data
  387. <h3>See also:</h3>
  388. <ul>
  389. <li><a href="#urldecode">
  390. urldecode
  391. </a>
  392. </ul>
  393. </dd>
  394. <dt><a name="urlencode_params"></a><strong>urlencode_params</strong>&nbsp;(tbl)</dt>
  395. <dd>
  396. Encode each key-value-pair in given table to x-www-urlencoded format,
  397. separated by "&". Tables are encoded as parameters with multiple values by
  398. repeating the parameter name with each value.
  399. <h3>Parameters</h3>
  400. <ul>
  401. <li>
  402. tbl: Table with the values
  403. </li>
  404. </ul>
  405. <h3>Return value:</h3>
  406. String containing encoded values
  407. <h3>See also:</h3>
  408. <ul>
  409. <li><a href="#urldecode_params">
  410. urldecode_params
  411. </a>
  412. </ul>
  413. </dd>
  414. </dl>
  415. </div> <!-- id="content" -->
  416. </div> <!-- id="main" -->
  417. <div id="about">
  418. <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>
  419. </div> <!-- id="about" -->
  420. </div> <!-- id="container" -->
  421. </body>
  422. </html>