Details
Description
When FollowRedirectsAttribute is set, the redirected request will almost always be changed to the "GET" HTTP verb. This is correct for some response codes (303, in practice 302) but is incorrect for at least 307.
From looking at the code, it looks like only the "HEAD" verb is preserved for all redirection codes.
Here's test code:
QCoreApplication a(argc, argv); int redirectCode = 307; QByteArray receivedMethod; QTcpServer server; server.listen(QHostAddress::LocalHost); qDebug() << "Listening at" << server.serverPort(); QObject::connect(&server, &QTcpServer::newConnection, &a, [&] { while (QTcpSocket *socket = server.nextPendingConnection()) { QObject::connect(socket, &QTcpSocket::disconnected, socket, &QTcpSocket::deleteLater); auto buffer = new QByteArray; QObject::connect(socket, &QIODevice::readyRead, &a, [&, socket, buffer] { buffer->append(socket->readAll()); if (!buffer->endsWith("\r\n")) return; auto tokens = buffer->split(' '); qDebug() << "SERVER: " << tokens[0] << tokens[1]; QTextStream stream(socket); if (tokens[1] == "/redirectme") { stream << QString("HTTP/1.0 %1 Redirectme\r\n").arg(redirectCode); stream << QString("Location: http://localhost:%1/target\r\n").arg(server.serverPort()); } else { stream << "HTTP/1.0 200 Ok\r\n"; receivedMethod = tokens[0]; } stream << "\r\n"; stream.flush(); socket->flush(); socket->close(); socket->deleteLater(); }); } }); QNetworkAccessManager nam; for (int code: {301, 302, 303, 307, 308}) { qDebug() << "\nTesting redirect code" << code; redirectCode = code; QNetworkRequest req; req.setUrl(QString("http://localhost:%1/redirectme").arg(server.serverPort())); req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); auto reply = nam.sendCustomRequest(req, "PROPFIND"); qDebug() << "CLIENT sends a request, server will redirect"; QEventLoop loop; QObject::connect(reply, &QNetworkReply::finished, &a, [&]{ qDebug() << "CLIENT finished. The redirected request method was" << receivedMethod; loop.quit(); }); loop.exec(); }
Attachments
Issue Links
- is required for
-
QTBUG-63438 Improve (or even implement) the correct redirects support
- Closed