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 constexpr auto titlecase = [](QByteArrayView name) {
136 n.reserve(size_t(name.size()));
137 bool toUpperNext =
true;
138 for (
char c : name) {
139 n += toUpperNext ? QtMiscUtils::toAsciiUpper(c) : c;
140 toUpperNext = c ==
'-';
145 for (qsizetype i = 0; i < headers.size(); ++i) {
146 ba += titlecase(headers.nameAt(i));
148 ba += headers.valueAt(i);
151 if (request.d->operation == QHttpNetworkRequest::Post) {
153 if (request.headerField(
"content-type").isEmpty() && ((request.d->uploadByteDevice && request.d->uploadByteDevice->size() > 0) || request.d->url.hasQuery())) {
157 qWarning(
"content-type missing in HTTP POST, defaulting to application/x-www-form-urlencoded. Use QNetworkRequest::setHeader() to fix this problem.");
158 ba +=
"Content-Type: application/x-www-form-urlencoded\r\n";
160 if (!request.d->uploadByteDevice && request.d->url.hasQuery()) {
161 QByteArray query = request.d->url.query(QUrl::FullyEncoded).toLatin1();
162 ba +=
"Content-Length: ";
163 ba += QByteArray::number(query.size());
178QHttpNetworkRequest::QHttpNetworkRequest(
const QUrl &url, Operation operation, Priority priority)
179 : d(
new QHttpNetworkRequestPrivate(operation, priority, url))
411bool QHttpNetworkRequest::methodIsIdempotent()
const
413 using Op = Operation;
414 constexpr auto knownSafe = std::array{ Op::Get, Op::Head, Op::Put, Op::Trace, Op::Options };
415 return std::any_of(knownSafe.begin(), knownSafe.end(),
416 [currentOp = d->operation](
auto op) {
return op == currentOp; });