Solved setApplicationProxy and QNetworkAccessManager proxyAuthenticationRequired
-
Hi,
I am using Qt 5.5.1.
If I set the global proxy settings with the static method setApplicationProxy (with username and password) everything works as expected, except some times when, after some hours of "good" http posts thru the proxy, I get the proxyAuthenticationRequired error from the QNetworkAccessManager object that I use for making the requests.
The proxy is a squid 3 with digest authentication.
It seems like Qt is loosing the credentials that I set with setApplicationProxy...is this a normal behavior? Must I refill the credentials in the proxyAuthenticationRequired slot using the authenticator object? -
Hi and welcome to devnet,
I'm by no way specialist but doesn't the squid have a validity interval for the digest ? If so you're likely hitting that value and must generate a new one providing again your credentials.
-
Thank you for the answer.
Yes it could be...but what is strange to me is that when the proxyAuthenticationRequired signal arrives, if I retrieve the application proxy settings by calling the static method "applicationProxy" inside the returned QNetworkProxy object I can find the right credentials (username and password are still the one I've set with setApplicationProxy).
I had a look at the qnetworkaccessmanager code and it seems that, before firing the signal, it tries to get the "cached" credentials (using fetchCachedProxyCredentials) but it does not look at the credential set using setApplicationProxy...this could be a bug IMHO.
Otherwise I'd like to understand if this is a wanted behavior. -
AFAIK, fetchCachedProxyCredentials gets the application proxy if you are using the default proxy.
Can you share how you setup your QNetworkAccessManager and your squid proxy ?
-
Thank you for your time.
BTW I've soved the problem.
Now in the proxyAuthenticationRequired slot of the QNetworkAccessManager object I get the global proxy settings object and I set username and password in the authenticator object passed to the slot.
It seems to work and when it happens I see messages like these:QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://xxxx@xxxxxxx.xxxx:80#TestSquidProxy' (access/qnetworkaccesscache.cpp:255, void QNetworkAccessCache::addEntry(const QByteArray&, QNetworkAccessCache::CacheableObject*))
QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://xxxx@xxxxxxx.xxx:80' (access/qnetworkaccesscache.cpp:255, void QNetworkAccessCache::addEntry(const QByteArray&, QNetworkAccessCache::CacheableObject*))
QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://xxxxxxx.xxx:80' (access/qnetworkaccesscache.cpp:255, void QNetworkAccessCache::addEntry(const QByteArray&, QNetworkAccessCache::CacheableObject*))
So it seems it was something related to cached credentials.
Thank you for your help.