QGrpcHttp2Channel Class

The QGrpcHttp2Channel class is an HTTP/2-based of QAbstractGrpcChannel, based on Qt Network HTTP/2 implementation. More...

Header: #include <QGrpcHttp2Channel>
CMake: find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
Since: Qt 6.5
In QML: GrpcHttp2Channel
Inherits: QAbstractGrpcChannel

Public Functions

QGrpcHttp2Channel(const QUrl &hostUri)
QGrpcHttp2Channel(const QUrl &hostUri, const QGrpcChannelOptions &options)
virtual ~QGrpcHttp2Channel() override
QUrl hostUri() const

Detailed Description

Uses QGrpcChannelOptions and QGrpcCallOptions to control the HTTP/2 communication with the server.

Use QGrpcChannelOptions to set the SSL configuration, application-specific HTTP/2 headers, and connection timeouts.

QGrpcCallOptions control channel parameters for the specific unary call or gRPC stream.

QGrpcHttp2Channel uses QGrpcChannelOptions to select the serialization format for the protobuf messages. The serialization format can be set either using the content-type metadata or by setting the QGrpcChannelOptions::serializationFormat directly.

Using the following example you can create a QGrpcHttp2Channel with the JSON serialization format using the content-type metadata:

auto channelJson = std::make_shared<
QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) }
                       .withMetadata({ { "content-type"_ba,
                                         "application/grpc+json"_ba } }));

Also you can use own serializer and custom content-type as following:

class DummySerializer : public QAbstractProtobufSerializer
{
    ...
};
auto channel = std::make_shared<
    QGrpcHttp2Channel>(QUrl("http://localhost:50051", QUrl::StrictMode), QGrpcChannelOptions{}
                       .setSerializationFormat(QGrpcSerializationFormat{ "dummy",
                                                  std::make_shared<DummySerializer>() }));

QGrpcHttp2Channel will use the DummySerializer to serialize and deserialize protobuf message and use the content-type: application/grpc+dummy header when sending HTTP/2 requests to server.

QGrpcChannelOptions::serializationFormat has higher priority and if the content-type metadata suffix doesn't match the QGrpcSerializationFormat::suffix of the specified QGrpcChannelOptions::serializationFormat QGrpcHttp2Channel produces warning.

See also QGrpcChannelOptions, QGrpcCallOptions, and QSslConfiguration.

Member Function Documentation

[explicit] QGrpcHttp2Channel::QGrpcHttp2Channel(const QUrl &hostUri)

Constructs QGrpcHttp2Channel with hostUri.

[explicit] QGrpcHttp2Channel::QGrpcHttp2Channel(const QUrl &hostUri, const QGrpcChannelOptions &options)

Constructs QGrpcHttp2Channel with hostUri and options.

[override virtual noexcept] QGrpcHttp2Channel::~QGrpcHttp2Channel()

Destroys the QGrpcHttp2Channel object.

QUrl QGrpcHttp2Channel::hostUri() const

Returns the host URI for this channel.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.