51 return QHttpNetworkHeaderPrivate::operator==(other)
52 && (operation == other.operation)
53 && (fullLocalServerName == other.fullLocalServerName)
54 && (priority == other.priority)
55 && (uploadByteDevice == other.uploadByteDevice)
56 && (autoDecompress == other.autoDecompress)
57 && (pipeliningAllowed == other.pipeliningAllowed)
58 && (http2Allowed == other.http2Allowed)
59 && (http2Direct == other.http2Direct)
60 && (h2cAllowed == other.h2cAllowed)
62 && (operation != QHttpNetworkRequest::Custom || (customVerb == other.customVerb))
63 && (withCredentials == other.withCredentials)
65 && (preConnect == other.preConnect)
66 && (redirectPolicy == other.redirectPolicy)
67 && (peerVerifyName == other.peerVerifyName)
68 && (needResendWithCredentials == other.needResendWithCredentials)
72QByteArray QHttpNetworkRequest::methodName()
const
74 switch (d->operation) {
75 case QHttpNetworkRequest::Get:
77 case QHttpNetworkRequest::Head:
79 case QHttpNetworkRequest::Post:
81 case QHttpNetworkRequest::Options:
83 case QHttpNetworkRequest::Put:
85 case QHttpNetworkRequest::Delete:
87 case QHttpNetworkRequest::Trace:
89 case QHttpNetworkRequest::Connect:
91 case QHttpNetworkRequest::Custom:
99QByteArray QHttpNetworkRequest::uri(
bool throughProxy)
const
101 QUrl::FormattingOptions format(QUrl::RemoveFragment | QUrl::RemoveUserInfo | QUrl::FullyEncoded);
104 if (d->operation == QHttpNetworkRequest::Post && !d->uploadByteDevice)
105 format |= QUrl::RemoveQuery;
108 format |= QUrl::RemoveScheme | QUrl::RemoveAuthority;
110 if (copy.path().isEmpty())
111 copy.setPath(QStringLiteral(
"/"));
113 format |= QUrl::NormalizePathSegments;
114 QByteArray uri = copy.toEncoded(format);
120 const QHttpHeaders headers = request.header();
122 ba.reserve(40 + headers.size() * 25);
124 ba += request.methodName();
126 ba += request.uri(throughProxy);
129 ba += QByteArray::number(request.majorVersion());
131 ba += QByteArray::number(request.minorVersion());
134 for (qsizetype i = 0; i < headers.size(); ++i) {
135 ba += headers.nameAt(i);
137 ba += headers.valueAt(i);
140 if (request.d->operation == QHttpNetworkRequest::Post) {
142 if (request.headerField(
"content-type").isEmpty() && ((request.d->uploadByteDevice && request.d->uploadByteDevice->size() > 0) || request.d->url.hasQuery())) {
146 qWarning(
"content-type missing in HTTP POST, defaulting to application/x-www-form-urlencoded. Use QNetworkRequest::setHeader() to fix this problem.");
147 ba +=
"Content-Type: application/x-www-form-urlencoded\r\n";
149 if (!request.d->uploadByteDevice && request.d->url.hasQuery()) {
150 QByteArray query = request.d->url.query(QUrl::FullyEncoded).toLatin1();
151 ba +=
"Content-Length: ";
152 ba += QByteArray::number(query.size());
167QHttpNetworkRequest::QHttpNetworkRequest(
const QUrl &url, Operation operation, Priority priority)
168 : d(
new QHttpNetworkRequestPrivate(operation, priority, url))
400bool QHttpNetworkRequest::methodIsIdempotent()
const
402 using Op = Operation;
403 constexpr auto knownSafe = std::array{ Op::Get, Op::Head, Op::Put, Op::Trace, Op::Options };
404 return std::any_of(knownSafe.begin(), knownSafe.end(),
405 [currentOp = d->operation](
auto op) {
return op == currentOp; });