http.luadoc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. ---[[
  2. LuCI Web Framework high-level HTTP functions.
  3. ]]
  4. module "luci.http"
  5. ---[[
  6. Close the HTTP-Connection.
  7. @class function
  8. @name close
  9. ]]
  10. ---[[
  11. Return the request content if the request was of unknown type.
  12. @class function
  13. @name content
  14. @return HTTP request body
  15. @return HTTP request body length
  16. ]]
  17. ---[[
  18. Get a certain HTTP input value or a table of all input values.
  19. @class function
  20. @name formvalue
  21. @param name Name of the GET or POST variable to fetch
  22. @param noparse Don't parse POST data before getting the value
  23. @return HTTP input value or table of all input value
  24. ]]
  25. ---[[
  26. Get a table of all HTTP input values with a certain prefix.
  27. @class function
  28. @name formvaluetable
  29. @param prefix Prefix
  30. @return Table of all HTTP input values with given prefix
  31. ]]
  32. ---[[
  33. Get the value of a certain HTTP-Cookie.
  34. @class function
  35. @name getcookie
  36. @param name Cookie Name
  37. @return String containing cookie data
  38. ]]
  39. ---[[
  40. Get the value of a certain HTTP environment variable
  41. or the environment table itself.
  42. @class function
  43. @name getenv
  44. @param name Environment variable
  45. @return HTTP environment value or environment table
  46. ]]
  47. ---[[
  48. Set a handler function for incoming user file uploads.
  49. @class function
  50. @name setfilehandler
  51. @param callback Handler function
  52. ]]
  53. ---[[
  54. Send a HTTP-Header.
  55. @class function
  56. @name header
  57. @param key Header key
  58. @param value Header value
  59. ]]
  60. ---[[
  61. Set the mime type of following content data.
  62. @class function
  63. @name prepare_content
  64. @param mime Mimetype of following content
  65. ]]
  66. ---[[
  67. Get the RAW HTTP input source
  68. @class function
  69. @name source
  70. @return HTTP LTN12 source
  71. ]]
  72. ---[[
  73. Set the HTTP status code and status message.
  74. @class function
  75. @name status
  76. @param code Status code
  77. @param message Status message
  78. ]]
  79. ---[[
  80. Send a chunk of content data to the client.
  81. This function is as a valid LTN12 sink.
  82. If the content chunk is nil this function will automatically invoke close.
  83. @class function
  84. @name write
  85. @param content Content chunk
  86. @param src_err Error object from source (optional)
  87. @see close
  88. ]]
  89. ---[[
  90. Splice data from a filedescriptor to the client.
  91. @class function
  92. @name splice
  93. @param fp File descriptor
  94. @param size Bytes to splice (optional)
  95. ]]
  96. ---[[
  97. Redirects the client to a new URL and closes the connection.
  98. @class function
  99. @name redirect
  100. @param url Target URL
  101. ]]
  102. ---[[
  103. Create a querystring out of a table of key - value pairs.
  104. @class function
  105. @name build_querystring
  106. @param table Query string source table
  107. @return Encoded HTTP query string
  108. ]]
  109. ---[[
  110. Return the URL-decoded equivalent of a string.
  111. @class function
  112. @name urldecode
  113. @param str URL-encoded string
  114. @param no_plus Don't decode + to " "
  115. @return URL-decoded string
  116. @see urlencode
  117. ]]
  118. ---[[
  119. Return the URL-encoded equivalent of a string.
  120. @class function
  121. @name urlencode
  122. @param str Source string
  123. @return URL-encoded string
  124. @see urldecode
  125. ]]
  126. ---[[
  127. Send the given data as JSON encoded string.
  128. @class function
  129. @name write_json
  130. @param data Data to send
  131. ]]
  132. ---[[
  133. Extract and split urlencoded data pairs, separated bei either "&" or ";"
  134. from given url or string. Returns a table with urldecoded values.
  135. Simple parameters are stored as string values associated with the parameter
  136. name within the table. Parameters with multiple values are stored as array
  137. containing the corresponding values.
  138. @class function
  139. @name urldecode_params
  140. @param url The url or string which contains x-www-urlencoded form data
  141. @param tbl Use the given table for storing values (optional)
  142. @return Table containing the urldecoded parameters
  143. @see urlencode_params
  144. ]]
  145. ---[[
  146. Encode each key-value-pair in given table to x-www-urlencoded format,
  147. separated by "&".
  148. Tables are encoded as parameters with multiple values by repeating the
  149. parameter name with each value.
  150. @class function
  151. @name urlencode_params
  152. @param tbl Table with the values
  153. @return String containing encoded values
  154. @see urldecode_params
  155. ]]
  156. ---[[
  157. Decode a mime encoded http message body with multipart/form-data Content-Type.
  158. Stores all extracted data associated with its parameter name
  159. in the params table within the given message object. Multiple parameter
  160. values are stored as tables, ordinary ones as strings.
  161. If an optional file callback function is given then it is fed with the
  162. file contents chunk by chunk and only the extracted file name is stored
  163. within the params table. The callback function will be called subsequently
  164. with three arguments:
  165. o Table containing decoded (name, file) and raw (headers) mime header data
  166. o String value containing a chunk of the file data
  167. o Boolean which indicates whether the current chunk is the last one (eof)
  168. @class function
  169. @name mimedecode_message_body
  170. @param src Ltn12 source function
  171. @param msg HTTP message object
  172. @param filecb File callback function (optional)
  173. @return Value indicating successful operation (not nil means "ok")
  174. @return String containing the error if unsuccessful
  175. @see parse_message_header
  176. ]]
  177. ---[[
  178. Decode an urlencoded http message body with application/x-www-urlencoded
  179. Content-Type.
  180. Stores all extracted data associated with its parameter name in the params
  181. table within the given message object. Multiple parameter values are stored
  182. as tables, ordinary ones as strings.
  183. @class function
  184. @name urldecode_message_body
  185. @param src Ltn12 source function
  186. @param msg HTTP message object
  187. @return Value indicating successful operation (not nil means "ok")
  188. @return String containing the error if unsuccessful
  189. @see parse_message_header
  190. ]]
  191. ---[[
  192. Try to extract and decode a http message body from the given ltn12 source.
  193. This function will examine the Content-Type within the given message object
  194. to select the appropriate content decoder.
  195. Currently the application/x-www-urlencoded and application/form-data
  196. mime types are supported. If the encountered content encoding can't be
  197. handled then the whole message body will be stored unaltered as "content"
  198. property within the given message object.
  199. @class function
  200. @name parse_message_body
  201. @param src Ltn12 source function
  202. @param msg HTTP message object
  203. @param filecb File data callback (optional, see mimedecode_message_body())
  204. @return Value indicating successful operation (not nil means "ok")
  205. @return String containing the error if unsuccessful
  206. @see parse_message_header
  207. ]]