Cache the :scheme HTTP/2 header

It's not mutable during QGrpcHttp2ChannelPrivate lifetime, so we
may cache it.

Pick-to: 6.8 6.9
Change-Id: I2b84a4ec46acfca488d00d527e180a6e3fc430f1
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Alexey Edelev 2025-01-28 21:24:31 +01:00
parent 7d939f6e2e
commit 073429bfb1
1 changed files with 5 additions and 2 deletions

View File

@ -269,6 +269,7 @@ public:
[[nodiscard]] const QByteArray &contentType() const { return m_contentType; }
[[nodiscard]] const QByteArray &authorityHeader() const { return m_authorityHeader; }
[[nodiscard]] const QByteArray &schemeHeader() const { return m_schemeHeader; }
std::shared_ptr<QAbstractProtobufSerializer> serializer;
QUrl hostUri;
@ -314,6 +315,7 @@ private:
std::function<void()> m_reconnectFunction;
QByteArray m_authorityHeader;
QByteArray m_schemeHeader;
Q_DISABLE_COPY_MOVE(QGrpcHttp2ChannelPrivate)
};
@ -465,8 +467,7 @@ void Http2Handler::prepareInitialRequest(QGrpcOperationContext *operationContext
{ AuthorityHeader.toByteArray(), channel->authorityHeader() },
{ MethodHeader.toByteArray(), "POST"_ba },
{ PathHeader.toByteArray(), QByteArray('/' + service + '/' + method) },
{ SchemeHeader.toByteArray(),
channel->isLocalSocket() ? "http"_ba : channel->hostUri.scheme().toLatin1() },
{ SchemeHeader.toByteArray(), channel->schemeHeader() },
{ ContentTypeHeader.toByteArray(), channel->contentType() },
{ GrpcServiceNameHeader.toByteArray(), { service } },
{ GrpcAcceptEncodingHeader.toByteArray(), "identity,deflate,gzip"_ba },
@ -749,6 +750,8 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
m_authorityHeader += QByteArray::number(hostUri.port());
}
m_schemeHeader = isLocalSocket() ? "http"_ba : hostUri.scheme().toLatin1();
m_reconnectFunction();
}