aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-16 23:21:49 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-16 23:21:49 +0000
commit27c8ae30aaef25d537669062d5f7f929eec18032 (patch)
tree1a141b842e1b5ed49c0bc4385cabdae95c204e83
parent9fc682a106f13901b60a665619fc61d9dae49fb0 (diff)
downloadluasocket-27c8ae30aaef25d537669062d5f7f929eec18032.tar.gz
luasocket-27c8ae30aaef25d537669062d5f7f929eec18032.tar.bz2
luasocket-27c8ae30aaef25d537669062d5f7f929eec18032.zip
Updated the HTTP manual. Finaly done.
-rw-r--r--doc/http.html148
-rw-r--r--doc/reference.html4
-rw-r--r--doc/url.html14
3 files changed, 71 insertions, 95 deletions
diff --git a/doc/http.html b/doc/http.html
index a621ec7..9125df7 100644
--- a/doc/http.html
+++ b/doc/http.html
@@ -48,11 +48,9 @@ implementation conforms to the HTTP/1.1 standard,
48 48
49<p> 49<p>
50The module exports functions that provide HTTP functionality in different 50The module exports functions that provide HTTP functionality in different
51levels of abstraction, from the simple 51levels of abstraction. From the simple
52<a href="#get"><tt>get</tt></a> function, through the generic 52string oriented requests, through generic
53<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based 53<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based, down to even lower-level if you bother to look through the source code.
54<a href="#request"><tt>request</tt></a> function, down to
55even lower-level if you bother to look through the source code.
56</p> 54</p>
57 55
58<p> 56<p>
@@ -118,72 +116,10 @@ the HTTP module:
118<li> <tt>USERAGENT</tt>: default user agent reported to server. 116<li> <tt>USERAGENT</tt>: default user agent reported to server.
119</ul> 117</ul>
120 118
121<!-- http.get +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
122
123<p class=name id=get>
124http.<b>get(</b>url<b>)</b><br>
125</p>
126
127<p class=description>
128Performs the HTTP method <tt>GET</tt>.
129</p>
130
131<p class=parameters>
132<tt>Url</tt> identifies the entity to retrieve.
133</p>
134
135<p class=return>
136If successful, the function returns the response message body, the mime
137headers, and the status code. In case of failure, the
138function returns <tt><b>nil</b></tt> followed by an error message.
139</p>
140
141<p class=note>
142Note: The function is trivially implemented with the use of the
143<a href="#request"><tt>request</tt></a> function.
144</p>
145
146<pre class=example>
147-- load the http module
148http = require("http")
149
150-- connect to server "www.tecgraf.puc-rio.br" and retrieves this manual
151-- file from "/luasocket/http.html"
152b, h, c = http.get("http://www.tecgraf.puc-rio.br/luasocket/http.html")
153
154-- connect to server "www.tecgraf.puc-rio.br" and tries to retrieve
155-- "~diego/auth/index.html". Fails because authentication is needed.
156b, h, c = http.get("http://www.tecgraf.puc-rio.br/~diego/auth/index.html")
157-- b returns some useless page telling about the denied access,
158-- h returns authentication information
159-- and c returns with value 401 (Authentication Required)
160
161-- tries to connect to server "wrong.host" to retrieve "/"
162-- and fails because the host does not exist.
163r, e = http.get("http://wrong.host/")
164-- r is nil, and e returns with value "host not found"
165</pre>
166
167<!-- http.post ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
168
169<p class=name id=post>
170http.<b>post(</b>url, body<b>)</b><br>
171</p>
172
173<p class=description>
174Same as <a href="#get"><tt>get</tt></a>, except
175that the <tt>POST</tt> method is used and the request
176message <tt>body</tt> is sent along with the request.
177</p>
178
179<p class=note>
180Note: This function is also trivially implemented with the use of the
181<a href="#request"><tt>request</tt></a> function.
182</p>
183
184<!-- http.request ++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 119<!-- http.request ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
185 120
186<p class=name id=request> 121<p class=name id=request>
122http.<b>request(</b>url [, body]<b>)</b><br>
187http.<b>request{</b><br> 123http.<b>request{</b><br>
188&nbsp;&nbsp;url = <i>string</i>,<br> 124&nbsp;&nbsp;url = <i>string</i>,<br>
189&nbsp;&nbsp;[sink = <i>LTN12 sink</i>,]<br> 125&nbsp;&nbsp;[sink = <i>LTN12 sink</i>,]<br>
@@ -197,11 +133,23 @@ http.<b>request{</b><br>
197</p> 133</p>
198 134
199<p class=description> 135<p class=description>
200Performs the generic HTTP request, controlled by a request table. 136The request function has two forms. The simple form downloads
137a URL using the <tt>GET</tt> or <tt>POST</tt> method and is based
138on strings. The generic form performs any HTTP method and is
139<a href=http://lua-users.org/wiki/FiltersSourcesAndSinks>LTN12</a> based.
201</p> 140</p>
202 141
203<p class=parameters> 142<p class=parameters>
204The most important parameters are the <tt>url</tt> and the <em>simple</em> 143If the first argument of the <tt>request</tt> function is a string, it
144should be an <tt>url</tt>. In that case, if a <tt>body</tt>
145is provided as a string, the function will perform a <tt>POST</tt> method
146in the <tt>url</tt>. Otherwise, it performs a <tt>GET</tt> in the
147<tt>url</tt>
148</p>
149
150<p class=parameters>
151If the first argument is instead a table, the most important fields are
152the <tt>url</tt> and the <em>simple</em>
205<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> 153<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
206<tt>sink</tt> that will receive the downloaded content. 154<tt>sink</tt> that will receive the downloaded content.
207Any part of the <tt>url</tt> can be overridden by including 155Any part of the <tt>url</tt> can be overridden by including
@@ -232,20 +180,15 @@ function from automatically following 301 or 302 server redirect messages.
232 180
233<p class=return> 181<p class=return>
234In case of failure, the function returns <tt><b>nil</b></tt> followed by an 182In case of failure, the function returns <tt><b>nil</b></tt> followed by an
235error message. If successful, the function returns a table 183error message. If successful, the simple form returns the response
236with all components of the response message. The response table has the following form: 184body as a string, followed by the response status code, the response
185headers and the response status line. The complex function returns the same
186information, except the first return value is just the number 1 (the body
187goes to the <tt>sink</tt>).
237</p> 188</p>
238 189
239<blockquote><tt>
240respt = {<br>
241&nbsp;&nbsp;headers = <i>header-table</i>,<br>
242&nbsp;&nbsp;status = <i>string</i>,<br>
243&nbsp;&nbsp;code = <i>number</i>,<br>
244}
245</tt></blockquote>
246
247<p class=return> 190<p class=return>
248Even when the server fails to provide the contents of the requested URL (URL not found, for example), the 191Even when the server fails to provide the contents of the requested URL (URL not found, for example),
249it usually returns a message body (a web page informing the 192it usually returns a message body (a web page informing the
250URL was not found or some other useless page). To make sure the 193URL was not found or some other useless page). To make sure the
251operation was successful, check the returned status <tt>code</tt>. For 194operation was successful, check the returned status <tt>code</tt>. For
@@ -254,6 +197,35 @@ href="http://www.cs.princeton.edu/~diego/rfc/rfc2616.txt">RFC
2542616</a>. 1972616</a>.
255</p> 198</p>
256 199
200<p class=description>
201Here are a few examples with the simple interface:
202</p>
203
204<pre class=example>
205-- load the http module
206http = require("http")
207
208-- connect to server "www.tecgraf.puc-rio.br" and retrieves this manual
209-- file from "/luasocket/http.html"
210b = http.request("http://www.tecgraf.puc-rio.br/luasocket/http.html")
211
212-- connect to server "www.tecgraf.puc-rio.br" and tries to retrieve
213-- "~diego/auth/index.html". Fails because authentication is needed.
214b, c, h = http.request("http://www.tecgraf.puc-rio.br/~diego/auth/index.html")
215-- b returns some useless page telling about the denied access,
216-- h returns authentication information
217-- and c returns with value 401 (Authentication Required)
218
219-- tries to connect to server "wrong.host" to retrieve "/"
220-- and fails because the host does not exist.
221r, e = http.request("http://wrong.host/")
222-- r is nil, and e returns with value "host not found"
223</pre>
224
225<p class=description>
226And here is an example using the generic interface:
227</p>
228
257<pre class=example> 229<pre class=example>
258-- load the http module 230-- load the http module
259http = require("http") 231http = require("http")
@@ -261,12 +233,12 @@ http = require("http")
261-- Requests information about a document, without downloading it. 233-- Requests information about a document, without downloading it.
262-- Useful, for example, if you want to display a download gauge and need 234-- Useful, for example, if you want to display a download gauge and need
263-- to know the size of the document in advance 235-- to know the size of the document in advance
264respt = http.request { 236r, c, h = http.request {
265 method = "HEAD", 237 method = "HEAD",
266 url = "http://www.tecgraf.puc-rio.br/~diego" 238 url = "http://www.tecgraf.puc-rio.br/~diego"
267} 239}
268-- Would return the following headers: 240-- r is 1, c is 200, and h would return the following headers:
269-- respt.headers = { 241-- h = {
270-- date = "Tue, 18 Sep 2001 20:42:21 GMT", 242-- date = "Tue, 18 Sep 2001 20:42:21 GMT",
271-- server = "Apache/1.3.12 (Unix) (Red Hat/Linux)", 243-- server = "Apache/1.3.12 (Unix) (Red Hat/Linux)",
272-- ["last-modified"] = "Wed, 05 Sep 2001 06:11:20 GMT", 244-- ["last-modified"] = "Wed, 05 Sep 2001 06:11:20 GMT",
@@ -307,15 +279,11 @@ mime = require("mime")
307-- Connect to server "www.tecgraf.puc-rio.br" and tries to retrieve 279-- Connect to server "www.tecgraf.puc-rio.br" and tries to retrieve
308-- "~diego/auth/index.html", using the provided name and password to 280-- "~diego/auth/index.html", using the provided name and password to
309-- authenticate the request 281-- authenticate the request
310respt = http.request{ 282b, c, h = http.request("http://diego:password@www.tecgraf.puc-rio.br/~diego/auth/index.html")
311 url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html",
312 user = "diego",
313 password = "password"
314}
315 283
316-- Alternatively, one could fill the appropriate header and authenticate 284-- Alternatively, one could fill the appropriate header and authenticate
317-- the request directly. 285-- the request directly.
318respt = http.request { 286r, c = http.request {
319 url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html", 287 url = "http://www.tecgraf.puc-rio.br/~diego/auth/index.html",
320 headers = { authentication = "Basic " .. (mime.b64("diego:password")) } 288 headers = { authentication = "Basic " .. (mime.b64("diego:password")) }
321} 289}
diff --git a/doc/reference.html b/doc/reference.html
index 43aeea5..9ff6004 100644
--- a/doc/reference.html
+++ b/doc/reference.html
@@ -50,7 +50,7 @@
50<a href="ftp.html">FTP</a> 50<a href="ftp.html">FTP</a>
51<blockquote> 51<blockquote>
52<a href="ftp.html#get">get</a>, 52<a href="ftp.html#get">get</a>,
53<a href="ftp.html#put">put</a> 53<a href="ftp.html#put">put</a>.
54</blockquote> 54</blockquote>
55</blockquote> 55</blockquote>
56 56
@@ -59,8 +59,6 @@
59<blockquote> 59<blockquote>
60<a href="http.html">HTTP</a> 60<a href="http.html">HTTP</a>
61<blockquote> 61<blockquote>
62<a href="http.html#get">get</a>,
63<a href="http.html#post">post</a>,
64<a href="http.html#request">request</a>. 62<a href="http.html#request">request</a>.
65</blockquote> 63</blockquote>
66</blockquote> 64</blockquote>
diff --git a/doc/url.html b/doc/url.html
index cd699a2..1dbee52 100644
--- a/doc/url.html
+++ b/doc/url.html
@@ -36,13 +36,22 @@
36<h2 id=url>URL</h2> 36<h2 id=url>URL</h2>
37 37
38<p> 38<p>
39The module <tt>url.lua</tt> provides functions to parse, protect, 39The <tt>url</tt> namespace provides functions to parse, protect,
40and build URLs, as well as functions to compose absolute URLs 40and build URLs, as well as functions to compose absolute URLs
41from base and relative URLs, according to 41from base and relative URLs, according to
42<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC 42<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC
432396</a>. 432396</a>.
44</p> 44</p>
45 45
46<p>
47To obtain the <tt>url</tt> namespace, run:
48</p>
49
50<pre class=example>
51-- loads the URL module
52local url = require("url")
53</pre>
54
46<p> 55<p>
47An URL is defined by the following grammar: 56An URL is defined by the following grammar:
48</p> 57</p>
@@ -67,7 +76,8 @@ Builds an absolute URL from a base URL and a relative URL.
67</p> 76</p>
68 77
69<p class=parameters> 78<p class=parameters>
70<tt>Base</tt> is a string with the base URL and <tt>relative</tt> is a 79<tt>Base</tt> is a string with the base URL or
80a parsed URL table. <tt>Relative</tt> is a
71string with the relative URL. 81string with the relative URL.
72</p> 82</p>
73 83