Jan Tattermusch
0f1afec5a8
The very non-trivial upgrade of third_party/protobuf to 22.x This PR strives to be as small as possible and many changes that were compatible with protobuf 21.x and didn't have to be merged atomically with the upgrade were already merged. Due to the complexity of the upgrade, this PR wasn't created automatically by a tool, but manually. Subsequent upgraded of third_party/protobuf with our OSS release script should work again once this change is merged. This is best reviewed commit-by-commit, I tried to group changes in logical areas. Notable changes: - the upgrade of third_party/protobuf submodule, the bazel protobuf dependency itself - upgrade of UPB dependency to 22.x (in the past, we used to always upgrade upb to "main", but upb now has release branch as well). UPB needs to be upgraded atomically with protobuf since there's a de-facto circular dependency (new protobuf depends on new upb, which depends on new protobuf for codegen). - some protobuf and upb bazel rules are now aliases, so ` extract_metadata_from_bazel_xml.py` and `gen_upb_api_from_bazel_xml.py` had to be modified to be able to follow aliases and reach the actual aliased targets. - some protobuf public headers were renamed, so especially `src/compiler` needed to be updated to use the new headers. - protobuf and upb now both depend on utf8_range project, so since we bundle upb with grpc in some languages, we now have to bundle utf8_range as well (hence changes in build for python, PHP, objC, cmake etc). - protoc now depends on absl and utf8_range (previously protobuf had absl dependency, but not for the codegen part), so python's make_grpcio_tools.py required partial rewrite to be able to handle those dependencies in the grpcio_tools build. - many updates and fixes required for C++ distribtests (currently they all pass, but we'll probably need to follow up, make protobuf's and grpc's handling of dependencies more aligned and revisit the distribtests) - bunch of other changes mostly due to overhaul of protobuf's and upb's internal build layout. TODOs: - [DONE] make sure IWYU and clang_tidy_code pass - create a list of followups (e.g. work to reenable the few tests I had to disable and to remove workaround I had to use) - [DONE in cl/523706129] figure out problem(s) with internal import --------- Co-authored-by: Craig Tiller <ctiller@google.com> |
2 years ago | |
---|---|---|
.. | ||
BUILD | Add a test for a (now-illegal) build file construct (#27602) | 3 years ago |
CMakeLists.txt | CMake's better handling c++14 requirement (#31916) | 2 years ago |
Makefile | [protobuf] Upgrade third_party/protobuf to 22.x (#32606) | 2 years ago |
README.md | get rid of the https://grpc.io/release plague | 5 years ago |
greeter_client.cc | clang-format C++ examples (#25764) | 4 years ago |
greeter_server.cc | clang-format C++ examples (#25764) | 4 years ago |
README.md
Metadata Example
Overview
This example shows you how to add custom headers on the client and server and how to access them.
Custom metadata must follow the "Custom-Metadata" format listed in https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md, with the exception of binary headers, which don't have to be base64 encoded.
Get the tutorial source code
The example code for this and our other examples lives in the examples
directory. Clone this repository
at the latest stable release tag to your local machine by running the following command:
$ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc
Change your current directory to examples/cpp/metadata
$ cd examples/cpp/metadata
Generating gRPC code
To generate the client and server side interfaces:
$ make helloworld.grpc.pb.cc helloworld.pb.cc
Which internally invokes the proto-compiler as:
$ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto
$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
Try it!
Build client and server:
$ make
Run the server, which will listen on port 50051:
$ ./greeter_server
Run the client (in a different terminal):
$ ./greeter_client
If things go smoothly, you will see in the client terminal:
"Client received initial metadata from server: initial metadata value" "Client received trailing metadata from server: trailing metadata value" "Client received message: Hello World"
And in the server terminal:
"Header key: custom-bin , value: 01234567" "Header key: custom-header , value: Custom Value" "Header key: user-agent , value: grpc-c++/1.16.0-dev grpc-c/6.0.0-dev (linux; chttp2; gao)"
We did not add the user-agent metadata as a custom header. This shows how the gRPC framework adds some headers under the hood that may show up in the metadata map.