Skip to content

mandeepsandhu/qt-network-reply-ex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

qt-network-reply-ex

A wrapper class for automatically handling HTTP redirects.

Use this class to wrap your QNetworkReply object that you would get on initiating a request. Once the final url (after redirects) is reached, it emits the finished(QNetworkReply *). The parameter of the signal is the final reply object representing the last redirect.

Signals

  1. void finished(QNetworkReply *reply): Emitted on receiving the final (non-redirect) response from the server
  2. void redirected(const QUrl &url): Emitted on every redirect
  3. void error(QNetworkReply::NetworkError code): Relayed QNetworkReply error signal
  4. void redirectError(QtNetworkReplyEx::RedirectError error): Emitted on encountering a redirect related error

Redirect Errors

The following errors can occur on redirects:

  1. QtNetworkReplyEx::TooManyRedirects: Set when total number of redirects exceeds the maximum allowed redirects (QtNetworkReplyEx::maxRedirects()). Default is set to 10.
  2. QtNetworkReplyEx::UnsecureRedirect: Set when a redirect occurs from a secure (https) to a unsecure (http) connection and QtNetworkReplyEx::allowUnsecureRedirect() is false.
  3. QtNetworkReplyEx::InvalidRedirectProto: If rediect url's protocol is anything other than http ot https.

Usage

    ...
    QtNetworkReplyEx redirector(manager->get(networkRequest), this);

    connect(&redirector, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(onFinished(QNetworkReply*)));
    connect(&redirector, SIGNAL(redirected(QUrl)),
            this, SLOT(onRedirected(QUrl)));
    connect(&redirector, SIGNAL(redirectError(QtNetworkReplyEx::RedirectError)),
            this, SLOT(onRedirectError(QtNetworkReplyEx::RedirectError)));
    connect(&redirector, SIGNAL(error(QNetworkReply::NetworkError)),
            this, SLOT(onError(QNetworkReply::NetworkError)));
    ...
    ...

void onFinished(QNetworkReply *reply)
{
...
    qDebug() << "Original url is" << redirector.url();
    qDebug() << "Final url is" << reply->url();
...
}

About

A wrapper class for automatically handling HTTP redirects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages