aboutsummaryrefslogtreecommitdiff
path: root/docs/url.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/url.html')
-rw-r--r--docs/url.html82
1 files changed, 82 insertions, 0 deletions
diff --git a/docs/url.html b/docs/url.html
index e03b094..788f409 100644
--- a/docs/url.html
+++ b/docs/url.html
@@ -140,6 +140,14 @@ Lower level components, if specified,
140take precedence over high level components of the URL grammar. 140take precedence over high level components of the URL grammar.
141</p> 141</p>
142 142
143<p class=parameters>
144If <tt>host</tt> is not set, the host is taken from whichever single
145one of <tt>hostname</tt>, <tt>ipv4</tt> or <tt>ipv6</tt> is set
146(<tt>hosttype</tt> is ignored when building). It is an error to set more
147than one of <tt>hostname</tt>, <tt>ipv4</tt> or <tt>ipv6</tt> while
148<tt>host</tt> is absent.
149</p>
150
143<p class=return> 151<p class=return>
144The function returns a string with the built URL. 152The function returns a string with the built URL.
145</p> 153</p>
@@ -169,6 +177,62 @@ The function returns a string with the
169built <tt>&lt;path&gt;</tt> component. 177built <tt>&lt;path&gt;</tt> component.
170</p> 178</p>
171 179
180<!-- classify_host ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
181
182<p class=name id="classify_host">
183url.<b>classify_host(</b>host<b>)</b>
184</p>
185
186<p class=description>
187Classifies a raw <tt>&lt;host&gt;</tt> string into <tt>"name"</tt>,
188<tt>"ipv4"</tt> or <tt>"ipv6"</tt>. This is the same classification
189<a href="#parse"><tt>parse</tt></a> uses to fill in <tt>hosttype</tt>,
190exposed for callers that have a host string to classify without a full
191URL to parse.
192</p>
193
194<p class=parameters>
195<tt>Host</tt> is a host string as found in a URL's authority. Any
196<tt>:</tt> in <tt>host</tt> is taken as a sign of an IPv6 literal, so
197the enclosing <tt>[...]</tt> brackets URLs normally require for one are
198optional here: they are stripped when present, but classification does
199not depend on them.
200</p>
201
202<p class=return>
203The function returns two values: <tt>hosttype</tt>, one of
204<tt>"name"</tt>, <tt>"ipv4"</tt> or <tt>"ipv6"</tt>; and <tt>host</tt>,
205the input with any enclosing <tt>[...]</tt> brackets stripped, if
206present.
207</p>
208
209<p class=note>
210Note: classification is done by exclusion of shape, not by validating
211the address. A host is <tt>"ipv4"</tt> if it merely has the shape of
212four dot-separated digit groups &mdash; octet ranges are not checked,
213so <tt>"999.1.1.1"</tt> classifies as <tt>"ipv4"</tt> &mdash; and
214<tt>"ipv6"</tt> if it merely contains a <tt>:</tt>, whether or not that
215is a well-formed IPv6 address. Anything left over is <tt>"name"</tt>,
216whether or not it is actually a valid hostname.
217</p>
218
219<pre class=example>
220-- load url module
221url = require("socket.url")
222
223print(url.classify_host("example.com"))
224-- name example.com
225
226print(url.classify_host("192.168.1.1"))
227-- ipv4 192.168.1.1
228
229print(url.classify_host("[::1]"))
230-- ipv6 ::1
231
232print(url.classify_host("::1"))
233-- ipv6 ::1
234</pre>
235
172<!-- escape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 236<!-- escape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
173 237
174<p class=name id="escape"> 238<p class=name id="escape">
@@ -230,12 +294,28 @@ parsed_url = {<br>
230&nbsp;&nbsp;fragment = <i>string</i>,<br> 294&nbsp;&nbsp;fragment = <i>string</i>,<br>
231&nbsp;&nbsp;userinfo = <i>string</i>,<br> 295&nbsp;&nbsp;userinfo = <i>string</i>,<br>
232&nbsp;&nbsp;host = <i>string</i>,<br> 296&nbsp;&nbsp;host = <i>string</i>,<br>
297&nbsp;&nbsp;hosttype = <i>string</i>,<br>
298&nbsp;&nbsp;hostname = <i>string</i>,<br>
299&nbsp;&nbsp;ipv4 = <i>string</i>,<br>
300&nbsp;&nbsp;ipv6 = <i>string</i>,<br>
233&nbsp;&nbsp;port = <i>string</i>,<br> 301&nbsp;&nbsp;port = <i>string</i>,<br>
234&nbsp;&nbsp;user = <i>string</i>,<br> 302&nbsp;&nbsp;user = <i>string</i>,<br>
235&nbsp;&nbsp;password = <i>string</i><br> 303&nbsp;&nbsp;password = <i>string</i><br>
236} 304}
237</tt></blockquote> 305</tt></blockquote>
238 306
307<p class=parameters>
308When a host is present, <tt>hosttype</tt> is set to one of
309<tt>"name"</tt>, <tt>"ipv4"</tt> or <tt>"ipv6"</tt>, describing the
310syntax of <tt>host</tt>. Exactly one of <tt>hostname</tt>, <tt>ipv4</tt>
311or <tt>ipv6</tt> is then also set to the same value as <tt>host</tt>,
312matching <tt>hosttype</tt> &mdash; the other two are left <b><tt>nil</tt></b>.
313In case of an ipv6 address the brackets are stripped, both in <tt>host</tt> and <tt>ipv6</tt>.
314This classification is done by
315<a href="#classify_host"><tt>classify_host</tt></a>, by exclusion of
316shape rather than by validating the address (see its notes).
317</p>
318
239<pre class=example> 319<pre class=example>
240-- load url module 320-- load url module
241url = require("socket.url") 321url = require("socket.url")
@@ -248,6 +328,8 @@ parsed_url = url.parse("http://www.example.com/cgilua/index.lua?a=2#there")
248-- query = "a=2", 328-- query = "a=2",
249-- fragment = "there", 329-- fragment = "there",
250-- host = "www.puc-rio.br", 330-- host = "www.puc-rio.br",
331-- hosttype = "name",
332-- hostname = "www.puc-rio.br",
251-- } 333-- }
252 334
253parsed_url = url.parse("ftp://root:passwd@unsafe.org/pub/virus.exe;type=i") 335parsed_url = url.parse("ftp://root:passwd@unsafe.org/pub/virus.exe;type=i")