bool QHttpNetworkReplyPrivate::findChallenge(bool forProxy, QByteArray &challenge) const { challenge.clear(); // find out the type of authentication protocol requested. QByteArray header = forProxy ? "proxy-authenticate" : "www-authenticate"; // pick the best protocol (has to match parsing in QAuthenticatorPrivate) QList<QByteArray> challenges = headerFieldValues(header); for (int i = 0; i<challenges.size(); i++) { QByteArray line = challenges.at(i); // todo use qstrincmp if (!line.toLower().startsWith("negotiate")) challenge = line; } return !challenge.isEmpty(); }
QByteArray QHttpNetworkHeaderPrivate::headerField(const QByteArray &name, const QByteArray &defaultValue) const { QList<QByteArray> allValues = headerFieldValues(name); if (allValues.isEmpty()) return defaultValue; QByteArray result; bool first = true; foreach (const QByteArray &value, allValues) { if (!first) result += ", "; first = false; result += value; } return result; }
QAuthenticatorPrivate::Method QHttpNetworkReplyPrivate::authenticationMethod(bool isProxy) const { // The logic is same as the one used in void QAuthenticatorPrivate::parseHttpResponse() QAuthenticatorPrivate::Method method = QAuthenticatorPrivate::None; QByteArray header = isProxy ? "proxy-authenticate" : "www-authenticate"; QList<QByteArray> challenges = headerFieldValues(header); for (int i = 0; i<challenges.size(); i++) { QByteArray line = challenges.at(i).trimmed().toLower(); if (method < QAuthenticatorPrivate::Basic && line.startsWith("basic")) { method = QAuthenticatorPrivate::Basic; } else if (method < QAuthenticatorPrivate::Ntlm && line.startsWith("ntlm")) { method = QAuthenticatorPrivate::Ntlm; } else if (method < QAuthenticatorPrivate::DigestMd5 && line.startsWith("digest")) { method = QAuthenticatorPrivate::DigestMd5; } } return method; }