49 return QHttpNetworkHeaderPrivate::operator==(other)
50 && (operation == other.operation)
51 && (fullLocalServerName == other.fullLocalServerName)
52 && (priority == other.priority)
53 && (uploadByteDevice == other.uploadByteDevice)
54 && (autoDecompress == other.autoDecompress)
55 && (pipeliningAllowed == other.pipeliningAllowed)
56 && (http2Allowed == other.http2Allowed)
57 && (http2Direct == other.http2Direct)
58 && (h2cAllowed == other.h2cAllowed)
60 && (operation != QHttpNetworkRequest::Custom || (customVerb == other.customVerb))
61 && (withCredentials == other.withCredentials)
63 && (preConnect == other.preConnect)
64 && (redirectPolicy == other.redirectPolicy)
65 && (peerVerifyName == other.peerVerifyName)
66 && (needResendWithCredentials == other.needResendWithCredentials)
70QByteArray QHttpNetworkRequest::methodName()
const
72 switch (d->operation) {
73 case QHttpNetworkRequest::Get:
75 case QHttpNetworkRequest::Head:
77 case QHttpNetworkRequest::Post:
79 case QHttpNetworkRequest::Options:
81 case QHttpNetworkRequest::Put:
83 case QHttpNetworkRequest::Delete:
85 case QHttpNetworkRequest::Trace:
87 case QHttpNetworkRequest::Connect:
89 case QHttpNetworkRequest::Custom:
97QByteArray QHttpNetworkRequest::uri(
bool throughProxy)
const
99 QUrl::FormattingOptions format(QUrl::RemoveFragment | QUrl::RemoveUserInfo | QUrl::FullyEncoded);
102 if (d->operation == QHttpNetworkRequest::Post && !d->uploadByteDevice)
103 format |= QUrl::RemoveQuery;
106 format |= QUrl::RemoveScheme | QUrl::RemoveAuthority;
108 if (copy.path().isEmpty())
109 copy.setPath(QStringLiteral(
"/"));
111 format |= QUrl::NormalizePathSegments;
112 QByteArray uri = copy.toEncoded(format);
118 const QHttpHeaders headers = request.header();
120 ba.reserve(40 + headers.size() * 25);
122 ba += request.methodName();
124 ba += request.uri(throughProxy);
127 ba += QByteArray::number(request.majorVersion());
129 ba += QByteArray::number(request.minorVersion());
132 for (qsizetype i = 0; i < headers.size(); ++i) {
133 ba += headers.nameAt(i);
135 ba += headers.valueAt(i);
138 if (request.d->operation == QHttpNetworkRequest::Post) {
140 if (request.headerField(
"content-type").isEmpty() && ((request.d->uploadByteDevice && request.d->uploadByteDevice->size() > 0) || request.d->url.hasQuery())) {
144 qWarning(
"content-type missing in HTTP POST, defaulting to application/x-www-form-urlencoded. Use QNetworkRequest::setHeader() to fix this problem.");
145 ba +=
"Content-Type: application/x-www-form-urlencoded\r\n";
147 if (!request.d->uploadByteDevice && request.d->url.hasQuery()) {
148 QByteArray query = request.d->url.query(QUrl::FullyEncoded).toLatin1();
149 ba +=
"Content-Length: ";
150 ba += QByteArray::number(query.size());
165QHttpNetworkRequest::QHttpNetworkRequest(
const QUrl &url, Operation operation, Priority priority)
166 : d(
new QHttpNetworkRequestPrivate(operation, priority, url))
398bool QHttpNetworkRequest::methodIsIdempotent()
const
400 using Op = Operation;
401 constexpr auto knownSafe = std::array{ Op::Get, Op::Head, Op::Put, Op::Trace, Op::Options };
402 return std::any_of(knownSafe.begin(), knownSafe.end(),
403 [currentOp = d->operation](
auto op) {
return op == currentOp; });