Module socket.url
URI parsing, composition and relative URL resolution LuaSocket toolkit.
Author: Diego Nehab
Functions
| escape (s) | Encodes a string into its escaped hexadecimal representation Input s: binary string to be encoded Returns escaped representation of string binary |
| unescape (s) | Unencodes a escaped hexadecimal string into its binary representation Input s: escaped hexadecimal string to be unencoded Returns unescaped binary representation of escaped hexadecimal binary |
| 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
|
| build (parsed) | Rebuilds a parsed URL from its components. |
| absolute (base_url, relative_url) | Builds a absolute URL from a base and a relative URL according to RFC 2396 Input base_url relative_url Returns corresponding absolute url |
| parse_path (path) | Breaks a path into its segments, unescaping the segments Input path Returns segment: a table with one entry per segment |
| build_path (parsed, unsafe) | Builds a path component from its segments, escaping protected characters. |
Fields
| _VERSION | Module version |
Functions
- escape (s)
-
Encodes a string into its escaped hexadecimal representation
Input
s: binary string to be encoded
Returns
escaped representation of string binary
Parameters:
- s
- unescape (s)
-
Unencodes a escaped hexadecimal string into its binary representation
Input
s: escaped hexadecimal string to be unencoded
Returns
unescaped binary representation of escaped hexadecimal binary
Parameters:
- s
- 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
::= :// / ; ? # ::= @ : ::= [: ] :: = { /} Input url: uniform resource locator of request default: table with default values for each field Returns table with the following fields, where RFC naming conventions have been preserved: scheme, authority, userinfo, user, password, host, port, path, params, query, fragment Obs: the leading '/' in {/ } is considered part of Parameters:
- url
- default initialize default parameters
- build (parsed)
-
Rebuilds a parsed URL from its components.
Components are protected if any reserved or unallowed characters are found
Input
parsed: parsed URL, as returned by parse
Returns
a stringing with the corresponding URL
Parameters:
- parsed local ppath = _M.parse_path(parsed.path or "") local url = _M.build_path(ppath)
- absolute (base_url, relative_url)
-
Builds a absolute URL from a base and a relative URL according to RFC 2396
Input
base_url
relative_url
Returns
corresponding absolute url
Parameters:
- base_url
- relative_url
- parse_path (path)
-
Breaks a path into its segments, unescaping the segments
Input
path
Returns
segment: a table with one entry per segment
Parameters:
- path
- build_path (parsed, unsafe)
-
Builds a path component from its segments, escaping protected characters.
Input
parsed: path segments
unsafe: if true, segments are not protected before path is built
Returns
path: corresponding path stringing
Parameters:
- parsed
- unsafe