feat(tonic): add Request and Response extensions (#642)

Adds `tonic::Extensions` which is a newtype around `http::Extensions`.

Request extensions can be set by interceptors with
`Request::extensions_mut` and retrieved from RPCs with
`Request::extensions`. Extensions can also be set in tower middleware
and will be carried through to the RPC.

Since response extensions cannot be set by interceptors the main use
case is to set them in RPCs and retrieve them in tower middlewares.
Figured that might be useful.

Fixes https://github.com/hyperium/tonic/issues/255
This commit is contained in:
David Pedersen
2021-05-13 15:54:20 +02:00
committed by GitHub
parent 74ad0a998f
commit 352b0f584b
8 changed files with 321 additions and 13 deletions
+3
View File
@@ -17,6 +17,9 @@ bytes = "1.0"
[dev-dependencies]
tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "net"] }
tokio-stream = { version = "0.1.5", features = ["net"] }
tower-service = "0.3"
hyper = "0.14"
futures = "0.3"
[build-dependencies]
tonic-build = { path = "../../tonic-build" }