Parses a character string containing an RFC 3986 compliant URL as per NNG.

parse_url(url)

Arguments

url

character string containing a URL.

Value

A named character vector of length 10, comprising:

  • rawurl - the unparsed URL string.

  • scheme - the URL scheme, such as "http" or "inproc" (always lower case).

  • userinfo - the username and password if supplied in the URL string.

  • host - the full host part of the URL, including the port if present (separated by a colon).

  • hostname - the name of the host.

  • port - the port (if not specified, the default port if defined by the scheme).

  • path - the path, typically used with HTTP or WebSocket.

  • query - the query info (typically following ? in the URL).

  • fragment - used for specifying an anchor, the part after # in a URL.

  • requri - the full Request-URI (path[?query][#fragment]).

Values that cannot be determined are represented by an empty string

''.

Examples

parse_url("https://user:password@w3.org:8080/type/path?q=info#intro")
#>                                                     rawurl 
#> "https://user:password@w3.org:8080/type/path?q=info#intro" 
#>                                                     scheme 
#>                                                    "https" 
#>                                                   userinfo 
#>                                            "user:password" 
#>                                                       host 
#>                                              "w3.org:8080" 
#>                                                   hostname 
#>                                                   "w3.org" 
#>                                                       port 
#>                                                     "8080" 
#>                                                       path 
#>                                               "/type/path" 
#>                                                      query 
#>                                                   "q=info" 
#>                                                   fragment 
#>                                                    "intro" 
#>                                                     requri 
#>                                  "/type/path?q=info#intro" 
parse_url("tcp://192.168.0.2:5555")
#>                   rawurl                   scheme                 userinfo 
#> "tcp://192.168.0.2:5555"                    "tcp"                       "" 
#>                     host                 hostname                     port 
#>       "192.168.0.2:5555"            "192.168.0.2"                   "5555" 
#>                     path                    query                 fragment 
#>                       ""                       ""                       "" 
#>                   requri 
#>                       ""