Module neturl
neturl.lua - a robust url parser and builder
Bertrand Mansion, 2011-2012; License MIT
Functions
M:build () | builds the url |
buildQuery (tab, sep, key) | builds the querystring |
parseQuery (str, sep) | Parses the querystring to a table This function can parse multidimensional pairs and is mostly compatible with PHP usage of brackets in key names like ?param[key]=value |
M:setQuery (query) | set the url query |
M:setAuthority (authority) | set the authority part of the url The authority is parsed to find the user, password, port and host if available. |
parse (url) | Parse the url into the designated parts. |
removeDotSegments (path) | removes dots and slashes in urls when possible This function will also remove multiple slashes |
M:resolve (other) | builds a new url by using the one given as parameter and resolving paths |
M:normalize () | normalize a url path following some common normalization rules described on The URL normalization page of Wikipedia |
Tables
options | url options separator is set to `&` by default but could be anything like `&` or `;` |
services | list of known and common scheme ports as documented in IANA URI scheme list |
Functions
- M:build ()
-
builds the url
Returns:
-
a string representing the built url
- buildQuery (tab, sep, key)
-
builds the querystring
Parameters:
tab
: The key/value parameterssep
: The separator to use (optional)key
: The parent key if the value is multi-dimensional (optional)
Returns:
-
a string representing the built querystring
- parseQuery (str, sep)
-
Parses the querystring to a table
This function can parse multidimensional pairs and is mostly compatible
with PHP usage of brackets in key names like ?param[key]=value
Parameters:
str
: The querystring to parsesep
: The separator between key/value pairs, defaults to `&`
Returns:
-
a table representing the query key/value pairs
- M:setQuery (query)
-
set the url query
Parameters:
query
: Can be a string to parse or a table of key/value pairs
Returns:
-
a table representing the query key/value pairs
- M:setAuthority (authority)
-
set the authority part of the url
The authority is parsed to find the user, password, port and host if available.
Parameters:
authority
: The string representing the authority
Returns:
-
a string with what remains after the authority was parsed
- parse (url)
-
Parse the url into the designated parts.
Depending on the url, the following parts can be available:
scheme, userinfo, user, password, authority, host, port, path,
query, fragment
Parameters:
url
: Url string
Returns:
-
a table with the different parts and a few other functions
- removeDotSegments (path)
-
removes dots and slashes in urls when possible
This function will also remove multiple slashes
Parameters:
path
: The string representing the path to clean
Returns:
-
a string of the path without unnecessary dots and segments
- M:resolve (other)
-
builds a new url by using the one given as parameter and resolving paths
Parameters:
other
: A string or a table representing a url
Returns:
-
a new url table
- M:normalize ()
-
normalize a url path following some common normalization rules
described on The URL normalization page of Wikipedia
Returns:
-
the normalized path
Tables
- options
- url options separator is set to `&` by default but could be anything like `&` or `;`
- services
-
list of known and common scheme ports
as documented in IANA URI scheme list
Fields:
acap
:cap
:dict
:ftp
:gopher
:http
:https
:iax
:icap
:imap
:ipp
:ldap
:mtqp
:mupdate
:news
:nfs
:nntp
:rtsp
:sip
:snmp
:telnet
:tftp
:vemmi
:afs
:jms
:rsync
:prospero
:videotex
: