fn ishex(c byte) bool
fn new_values() Values
new_values returns a new Values struct for creating urlencoded query string parameters. it can also be to post form data with application/x-www-form-urlencoded. values.encode() will return the encoded data
fn parse(rawurl string) ?URL
parse parses rawurl into a URL structure. The rawurl may be relative (a path, without a host) or absolute (starting with a scheme). Trying to parse a hostname and path without a scheme is invalid but may not necessarily return an error, due to parsing ambiguities.
fn parse_query(query string) ?Values
Values maps a string key to a list of values. It is typically used for query parameters and form values. Unlike in the http.Header map, the keys in a Values map are case-sensitive. parseQuery parses the URL-encoded query string and returns a map listing the values specified for each key. parseQuery always returns a non-nil map containing all the valid query parameters found; err describes the first decoding error encountered, if any. Query is expected to be a list of key=value settings separated by ampersands or semicolons. A setting without an equals sign is interpreted as a key set to an empty value.
fn path_escape(s string) string
path_escape escapes the string so it can be safely placed inside a URL path segment, replacing special characters (including /) with %XX sequences as needed.
fn path_unescape(s string) ?string
path_unescape does the inverse transformation of path_escape, converting each 3-byte encoded substring of the form '%AB' into the hex-decoded byte 0xAB. It returns an error if any % is not followed by two hexadecimal digits. path_unescape is identical to query_unescape except that it does not unescape '+' to ' ' (space).
fn query_escape(s string) string
query_escape escapes the string so it can be safely placed inside a URL query.
fn query_unescape(s string) ?string
query_unescape does the inverse transformation of query_escape, converting each 3-byte encoded substring of the form '%AB' into the hex-decoded byte 0xAB. It returns an error if any % is not followed by two hexadecimal digits.
fn user(username string) &Userinfo
user returns a Userinfo containing the provided username and no password set.
fn valid_userinfo(s string) bool
valid_userinfo reports whether s is a valid userinfo string per RFC 3986 Section 3.2.1: userinfo = ( unreserved / pct-encoded / sub-delims / ':' ) unreserved = ALPHA / DIGIT / '-' / '.' / '_' / '~' sub-delims = '!' / '$' / '&' / ''' / '(' / ')' / '' / '+' / ',' / ';' / '=' It doesn't validate pct-encoded. The caller does that via fn unescape.
fn (v &Value) all() []string
Currently you will need to use all()[key].data once map[string][]string is implemented this will be fixed
fn (mut v Values) add(key string, value string)
add adds the value to key. It appends to any existing values associated with key.
fn (mut v Values) del(key string)
del deletes the values associated with key.
fn (v Values) encode() string
encode encodes the values into ``URL encoded'' form ('bar=baz&foo=quux') sorted by key.
fn (v &Values) get(key string) string
get gets the first value associated with the given key. If there are no values associated with the key, get returns a empty string.
fn (v &Values) get_all(key string) []string
get_all gets the all the values associated with the given key. If there are no values associated with the key, get returns a empty []string.
fn (mut v Values) set(key string, value string)
set sets the key to value. It replaces any existing values.
struct URL {
pub mut:
scheme string
opaque string
user &Userinfo
host string
path string
raw_path string
force_query bool
raw_query string
fragment string
}
A URL represents a parsed URL (technically, a URI reference). The general form represented is: [scheme:][//[[email protected]]host][/]path[?query][#fragment] URLs that do not start with a slash after the scheme are interpreted as: scheme:opaque[?query][#fragment] Note that the path field is stored in decoded form: /%47%6f%2f becomes /Go/. A consequence is that it is impossible to tell which slashes in the path were slashes in the raw URL and which were %2f. This distinction is rarely important, but when it is, the code should use raw_path, an optional field which only gets set if the default encoding is different from path. URL's String method uses the escaped_path method to obtain the path. See the escaped_path method for more details.
fn (mut u URL) set_path(p string) ?bool
set_path sets the path and raw_path fields of the URL based on the provided escaped path p. It maintains the invariant that raw_path is only specified when it differs from the default encoding of the path. For example: - set_path('/foo/bar') will set path='/foo/bar' and raw_path='' - set_path('/foo%2fbar') will set path='/foo/bar' and raw_path='/foo%2fbar' set_path will return an error only if the provided path contains an invalid escaping.
fn (u URL) str() string
str reassembles the URL into a valid URL string. The general form of the result is one of: scheme:opaque?query#fragment scheme://[email protected]/path?query#fragment If u.opaque is non-empty, String uses the first form; otherwise it uses the second form. Any non-ASCII characters in host are escaped. To obtain the path, String uses u.escaped_path(). In the second form, the following rules apply: - if u.scheme is empty, scheme: is omitted. - if u.user is nil, [email protected] is omitted. - if u.host is empty, host/ is omitted. - if u.scheme and u.host are empty and u.user is nil, the entire scheme://[email protected]/ is omitted. - if u.host is non-empty and u.path begins with a /, the form host/path does not add its own /. - if u.raw_query is empty, ?query is omitted. - if u.fragment is empty, #fragment is omitted.
fn (u &URL) is_abs() bool
is_abs reports whether the URL is absolute. Absolute means that it has a non-empty scheme.
fn (u &URL) parse(ref string) ?URL
parse parses a URL in the context of the receiver. The provided URL may be relative or absolute. parse returns nil, err on parse failure, otherwise its return value is the same as resolve_reference.
fn (u &URL) resolve_reference(ref &URL) ?URL
resolve_reference resolves a URI reference to an absolute URI from an absolute base URI u, per RFC 3986 Section 5.2. The URI reference may be relative or absolute. resolve_reference always returns a new URL instance, even if the returned URL is identical to either the base or reference. If ref is an absolute URL, then resolve_reference ignores base and returns a copy of ref.
fn (u &URL) query() Values
query parses raw_query and returns the corresponding values. It silently discards malformed value pairs. To check errors use parseQuery.
fn (u &URL) request_uri() string
request_uri returns the encoded path?query or opaque?query string that would be used in an HTTP request for u.
fn (u &URL) hostname() string
hostname returns u.host, stripping any valid port number if present. If the result is enclosed in square brackets, as literal IPv6 addresses are, the square brackets are removed from the result.
fn (u &URL) port() string
port returns the port part of u.host, without the leading colon. If u.host doesn't contain a port, port returns an empty string.