Library url
URI parsing, composition, and relative URL resolution.
A URL is represented as a table with the following entries:
schemefragmentqueryparamsauthorityuserinfopathportpassword
nil):
scheme://userinfo@password:authority:port/path;params?query#fragment
Authors:
| Diego Nehab |
| Eddie Bell <ejlbell@gmail.com> |
Source: http://nmap.org/svn/nselib/url.lua
Functions
| absolute (base_url, relative_url) |
Builds an absolute URL from a base and a relative URL according to RFC 2396. |
| build (parsed) |
Rebuilds a parsed URL from its components. |
| build_path (parsed, unsafe) |
Builds a path component from its segments, escaping protected characters. |
| build_query (query) |
Builds a query string from a table. |
| escape (s) |
Encodes a string into its escaped hexadecimal representation. |
| parse (url, default) |
Parses a URL and returns a table with all its parts according to RFC 2396. |
| parse_path (path) |
Breaks a path into its segments, unescaping the segments. |
| parse_query (query) |
Breaks a query string into name/value pairs. |
| unescape (s) |
Decodes an escaped hexadecimal string. |
Functions
- absolute (base_url, relative_url)
-
Builds an absolute URL from a base and a relative URL according to RFC 2396.
Parameters
- base_url: A base URL.
- relative_url: A relative URL.
Return value:
The corresponding absolute URL. - build (parsed)
-
Rebuilds a parsed URL from its components.
Components are protected if any reserved or unallowed characters are found.
Parameters
- parsed: Parsed URL, as returned by parse.
Return value:
A string with the corresponding URL. - build_path (parsed, unsafe)
-
Builds a path component from its segments, escaping protected characters.
Parameters
- parsed: Path segments.
- unsafe: If true, segments are not protected before path is built.
Return value:
The corresponding path string - build_query (query)
-
Builds a query string from a table.
This is the inverse of
parse_query.Parameters
-
query:
A dictionary table where
table['name']=value.
Return value:
A query string (like"name=value2&name=value2"). -
query:
A dictionary table where
- escape (s)
-
Encodes a string into its escaped hexadecimal representation.
Parameters
- s: Binary string to be encoded.
Return value:
Escaped representation of string. - parse (url, default)
-
Parses a URL and returns a table with all its parts according to RFC 2396.
The following grammar describes the names given to the URL parts.
<url> ::= <scheme>://<authority>/<path>;<params>?<query>#<fragment> <authority> ::= <userinfo>@<host>:<port> <userinfo> ::= <user>[:<password>] <path> :: = {<segment>/}<segment>The leading
/in/<path>is considered part of<path>.Parameters
- url: URL of request.
- default: Table with default values for each field.
Return value:
A table with the following fields, where RFC naming conventions have been preserved:scheme,authority,userinfo,user,password,host,port,path,params,query, andfragment. - parse_path (path)
-
Breaks a path into its segments, unescaping the segments.
Parameters
- path: A path to break.
Return value:
A table with one entry per segment. - parse_query (query)
-
Breaks a query string into name/value pairs.
This function takes a
<query>of the form"name1=value1&name2=value2"and returns a table containing the name-value pairs, with the name as the key and the value as its associated value.Parameters
- query: Query string.
Return value:
A table of name-value pairs following the patterntable["name"]=value. - unescape (s)
-
Decodes an escaped hexadecimal string.
Parameters
- s: Hexadecimal-encoded string.
Return value:
Decoded string.


