Tonic: Add Async Interceptors

Created on 21 Mar 2020  路  6Comments  路  Source: hyperium/tonic

Feature Request

Interceptor trait should support async functions.

Crates

tonic

Motivation

I would like to write an authentication interceptor which needs to make API calls to validate the incoming request, and it would be great if these could be async.

Most helpful comment

@blaind yes, it will be done via tower. I have not had much time to explore this but should hopefully soon :)

All 6 comments

@matthauck do these API calls need to happen on _each_ request or is this a case of refreshing a token? The reason I ask is because intentionally inteceptors were designed to not be async to make them simpler. We still provide the ability to use tower layers to intercept the whole HTTP2 request.

Yeah, something like validating an incoming token. Not necessarily every request, but potentially I suppose? Will look into intercepting at the tower layer.

So one suggestion is to actually use something from the arc-swap crate and spawn a background task to refresh a token. If you don't need to do some specific of async work per request, this method works well and its totally fine to load the arcswap in the sync interceptor fn.

Okay, great. thanks! we can close this issue then. "by design" :)

Are the async interceptors still open for consideration at some point (e.g. enough people request the feature)? I'd also like to be able to perform API calls (need to be immediate, so background call does not suffice).

@blaind yes, it will be done via tower. I have not had much time to explore this but should hopefully soon :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LucioFranco picture LucioFranco  路  6Comments

LucioFranco picture LucioFranco  路  7Comments

cthulhua picture cthulhua  路  3Comments

LucioFranco picture LucioFranco  路  6Comments

xmclark picture xmclark  路  10Comments