tufao  0.8.1
An asynchronous web framework for C++ built on top of Qt
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Tufao::Url Class Reference

This class provides a convenient interface for parsing URLs. More...

+ Collaboration diagram for Tufao::Url:

Public Member Functions

 Url (const QString &url=QString())
 Constructs a Tufao::Url to extract information from url.
 
 Url (const Url &url)
 Constructs a url as a copy of url.
 
 ~Url ()
 Destroys the url.
 
Urloperator= (const Url &url)
 Copies the url url and returns a reference to the copy.
 
QString scheme () const
 The protocol. More...
 
QString authority () const
 The authority. More...
 
QString path () const
 The path. More...
 
QString query () const
 The query string. More...
 
QString fragment () const
 The fragment id, also know as hash. More...
 
QString userinfo () const
 The userinfo. More...
 
QString hostname () const
 The hostname. More...
 
QString port () const
 The port. More...
 
QString username () const
 The username. More...
 
QString password () const
 The password. More...
 

Static Public Member Functions

static QByteArray url (Tufao::HttpServerRequest *request)
 Returns the url likely used by the client to perform the request. More...
 

Detailed Description

This class provides a convenient interface for parsing URLs.

Consider the following request coming from a user agent:

GET /search?q=foo&category=z HTTP/1.1
Host: example.com
...

The HttpServerRequest::url method will return the full url, making difficult to your application take the right decision with the object. This class will facilitate your job.

Some fields in URLs are optionals. If the optional fields are absent, the object will return empty strings for these fields, but if you try to use this class to parse an invalid url, you will get empty strings to all fields.

Note
Currently URL usage become commonplace and it's easy to find abbreviated URLs such as "www.example.com". These abbreviated URLs aren't valid and Tufao::Url won't parse them, but this isn't really a problem if you are using Tufao::Url just to parse urls received from Tufao::HttpServerRequest, because user agents implementing the HTTP protocol always send valid URLs.
See Also
QueryString to parse query strings.

Member Function Documentation

QString Tufao::Url::authority ( ) const

The authority.

The authority contains:

  • userinfo
  • hostname
  • port

In the url "scheme://userinfo@hostname:port/path?query#fragment" the authority will be "userinfo@hostname:port".

Other examples:

  • "username:password@hostname:port"
  • "userinfo@hostname:port"
  • "example.com"
QString Tufao::Url::fragment ( ) const

The fragment id, also know as hash.

In the url "scheme://userinfo@hostname:port/path?query#fragment" the hash will be "fragment".

Note
The frament id is used by the user agents in the html and not sent to the browser, so this field may be always empty when reading from Tufao::HttpServerRequest.

Other examples:

  • "title1"
  • "title1-1"
QString Tufao::Url::hostname ( ) const

The hostname.

In the url "scheme://userinfo@hostname:port/path?query#fragment" the hostname will be "hostname"

Other examples:

  • "hostname"
  • "example.com"
  • "127.0.0.1"
QString Tufao::Url::password ( ) const

The password.

Warning
This field is deprecated by the RFC and is here only to provide compatibility with old applications. It's usually unsafe to use passwords in urls and you problably don't want to use this technique.

This password is extracted from the userinfo assuming that userinfo uses the format "username:password".

In the url "scheme://userinfo@hostname:port/path?query#fragment" the password will be "".

Other examples:

  • "123456"
  • "42"
See Also
Tufao::Url::userinfo Tufao::Url::username
QString Tufao::Url::path ( ) const

The path.

In the url "scheme://userinfo@hostname:port/path?query#fragment" the path will be "/path".

Other examples:

  • "/index"
  • "/"
QString Tufao::Url::port ( ) const

The port.

In the url "scheme://userinfo@hostname:port/path?query#fragment" the port will be "port".

Other examples:

  • "80"
  • "443"
QString Tufao::Url::query ( ) const

The query string.

In the url "scheme://userinfo@hostname:port/path?query#fragment" the query string will be "query".

Other examples:

  • "type=penguin&name=tux"
  • "type=penguin&name=tux&age=20"
See Also
Tufao::QueryString
QString Tufao::Url::scheme ( ) const

The protocol.

In the url "scheme://userinfo@hostname:port/path?query#fragment" the scheme will be "scheme".

Other examples:

  • "http"
  • "ftp"
static QByteArray Tufao::Url::url ( Tufao::HttpServerRequest request)
static

Returns the url likely used by the client to perform the request.

Since
0.3
QString Tufao::Url::userinfo ( ) const

The userinfo.

The userinfo contains the username and password.

In the url "scheme://userinfo@hostname:port/path?query#fragment" the userinfo will be "userinfo".

Note
It's usually unsafe to use password in url.

Other examples:

  • "username:password"
  • "cn=br;user=admin"
  • "tux"
QString Tufao::Url::username ( ) const

The username.

Warning
This field is deprecated by the RFC and is here only to provide compatibility with old applications. You problably want to use Tufao::Url::userinfo.

This username is extracted from the userinfo assuming that userinfo uses the format "username:password".

In the url "scheme://userinfo@hostname:port/path?query#fragment" the username will be "userinfo".

Other examples:

  • "username"
  • "cn=br;user=admin"
  • "tux"
See Also
Tufao::Url::userinfo Tufao::Url::password

The documentation for this class was generated from the following file: