Class used for parsing URIs and URLs. Based on http://blog.stevenlevithan.com/archives/parseuri

Static variables

@:value(~/(?:^|&)([^&=]*)=?([^&]*)/)staticQUERY_REGEX:EReg = ~/(?:^|&)([^&=]*)=?([^&]*)/

@:value(~/^(?:([^:/?#]+):)?(?://((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?))?((((?:[^?#/]*/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/)staticURI_REGEX:EReg = ~/^(?:([^:/?#]+):)?(?://((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?))?((((?:[^?#/]*/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/

Static methods

staticparseQuery(query:String):Array<KVPair>

Constructor

new(uri:String)

Parses the given URI with regular expression and stores its parts in class variables. If the URI is malformed and cannot be parsed, the values will be null.

Parameters:

uri

the URI to be parsed.

Variables

anchor:String

The "#hash" part of the URI. In "https://example.com/index.php?action=upload&token=12345#header" this would be "header". In a more sophisicated example "https://example.com/index.php?action=upload#header=/abc/1234" that would be "header=/abc/1234". null if unspecified or malformed.

authority:String

Hostname and port along with the credentials found in this URI. In "https://john:[email protected]:443/page/index.html" this would be "john:[email protected]:443". null if unspecified or malformed.

directory:String

Directory where the target file pointed by the URI is located. Starts and ends with /. In "https://subdomain.example.com/files/website/index.php" this would be "/files/website/". null if unspecified or malformed.

file:String

Name of the file pointed by the URI. In "https://example.com/files/website/index.php?action=upload" this would be "index.php". null if unspecified or malformed.

host:String

Hostname (domain/IP) found in this URI. In "https://subdomain.example.com:443/index.html" this would be "subdomain.example.com" null if unspecified or malformed.

password:String

Password found in this URI. In "https://john:[email protected]/index.html" this would be "secret". null if unspecified or malformed.

path:String

Full path after the domain with directories, starting with /, without parameters In "https://subdomain.example.com/files/website/index.php?action=upload&token=12345#header" this would be "/files/website/index.php". null if unspecified or malformed.

port:String

Port used in this URI as String. In "https://subdomain.example.com:443/index.html" this would be "443". null if unspecified or malformed.

protocol:String

Protocol found in this URI. In "https://example.com/page/index.html" this would be "https". null if unspecified or malformed.

query:String

Query string passed to the URI. In "https://example.com/index.php?action=upload&token=12345#header" this would be "action=upload&token=12345". null if unspecified or malformed.

queryArray:Array<KVPair>

Value from query returned as an array of key-value pairs. In "https://example.com/index.php?action=upload&token=12345#header" the array would be [{k: "action", v: "upload"}, {k: "token", v: "12345"}]. If query is not present or the URI is malformed, it is just an empty array.

var uri = new URIParser("https://example.com/index.php?action=upload&token=12345#header");
for( q in uri.queryArray )
	trace( q.k + " = " + q.v); // action = upload
							   // token = 12345

relative:String

Full path after the host with all the directories and parameters, starting with /. In "https://subdomain.example.com/files/website/index.php?action=upload&token=12345#header" this would be "/files/website/index.php?action=upload&token=12345#header". null if unspecified or malformed.

source:String

The original URI from the constructor if the parsing is successful. Otherwise null.

user:String

Username found in this URI. In "https://john:[email protected]/index.html" this would be "john". null if unspecified or malformed.

userInfo:String

Credentials found in this URI. In "https://john:[email protected]/page/index.html" this would be "john:secret". null if unspecified or malformed.