NaviServer - programmable web server
4.99  5.0

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

ns_parseurl(n) 5.0.0a naviserver "NaviServer Built-in Commands"

Name

ns_parseurl - Parse a URL into its components

Table Of Contents

Synopsis

Description

COMMANDS

ns_parseurl ?-strict? url

This function parses the provided URL into its parts and returns these in the form of a Tcl dict. The function supports IP-literal notation as specified in RFC 3986.

The provided url might be an absolute URL (containing protocol and host), a protocol agnostic URL (starting with two slashes followed by hostname, as defined in RFC 3986) or a relative URL starting with everything that does not look likea a scheme. When the relative URL starts with a slash, it is separated into path and tail, otherwise it is parsed into tail (legacy NaviServer behavior). When the url contains a query or fragment, these are potentially returned in the dict.

When -strict is specified, the function performs a more thorough checking of the input characters (as defined in RFC 3986, but relaxed by errata #4942). Otherwise, the checking is kept to the bare minimum.

The resulting dict might contain the following elements: proto, userinfo, host, port, path, tail, query, and fragment.

ns_joinurl dict

This function is the inverse function of ns_parseurl. It receives the dict as produced from ns_parseurl and constructs a (partial) URL as implied by the dict members.

EXAMPLES

 % ns_parseurl http://openacs.org//projects/openacs/download/
 proto http host openacs.org path /projects/openacs/download tail {}
 
 % ns_parseurl {http://[::1]:80/index.html}
 proto http host ::1 port 80 path {} tail index.html
 
 % ns_parseurl /foo/bar.html
 path foo tail bar.html
 
 % ns_parseurl /top/query?x=1&y=2#pos1
 path top tail query query x=1&y=2 fragment pos1
 % ns_joinurl [ns_parseurl http://openacs.org/projects/openacs/download/]
 http://openacs.org/projects/openacs/download/

See Also

ns_absoluteurl, ns_parsefieldvalue, ns_parseheader, ns_parsehostport, ns_parsequery

Keywords

encoding, global built-in, parse, url