Currently, QNAM stalls when authentication is required (also see:
https://bugreports.qt-project.org/browse/QTBUG-16251).
Also, the connection between the authenticationRequired signal and the slot
must be a direct connection.
This is problematic when an application wants to show a login dialogbox for
instance.
I propose to change this implementation by using a delegate authenticator
instead.
class QAuthenticator
{
…
protected Q_SLOTS:
//this method should be called asynchronously from QNAM
void authenticate(QNetworkReply *reply) {
if (doAuthenticate(reply))
Q_EMIT authenticated();
else
Q_EMIT authenticationFailed();
}
...
protected:
//return false if the request should be stopped (authentication denied)
//return true if authentication should continue
virtual bool doAuthenticate(QNetworkReply *reply) = 0;
...
}
//example use
class MyAuthenticator: public QAuthenticator
{
bool doAuthenticate(QNetworkReply *reply) {
setUser();
setPassword();
setOption();
//whatever is required
return true;
}
}
The QNetworkRequest class would be extended with a setAuthenticator() method,
as follows:
class QNetworkRequest
{
...
void setAuthenticator(QAuthenticator *authenticator);
...
}
Usage:
MyAuthenticator *auth = new MyAuthenticator;
networkRequest.setAuthenticator(auth);
Another option is to add the setAuthenticator() method to the QNAM class.
When this would be implemented, the authenticationRequired() signal would
become obsolete.
What are your opinions on this?
Note: QWebSocketServer uses the same blocking signal for CORS authentication
(this was merely done to be inline with the QNAM way of working).
Cheers,
Kurt
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development