sdk-core icon indicating copy to clipboard operation
sdk-core copied to clipboard

[Feature Request] Dynamic HTTP headers

Open bergundy opened this issue 3 years ago • 3 comments

Currently it's only possible to configure static HTTP headers on the Client, we need to add a way to specify dynamic ones. A typical use case for this would be to refresh an auth token and users should not be required to recreate their workers for that.

bergundy avatar Apr 18 '22 19:04 bergundy

I think an Option<Fn(&mut HashMap<String, String>)> is reasonable at the client level (or tonic::metadata::MetadataMap or http::header::HeaderMap or whatever). But I wonder if we want to discuss general purpose gRPC interception lang callbacks at this time or save that discussion for later. I am thinking later since this is per call option and doesn't need to use gRPC interceptors from a Tonic POV.

cretz avatar Apr 18 '22 20:04 cretz

We will have to add general interceptors at some point but I don't think it has to be tied to dynamic headers. At some point soon we should also consider exposing the deadline for individual calls too.

bergundy avatar Apr 18 '22 20:04 bergundy

We already have dynamic headers, keeping this open for per request headers and deadline

bergundy avatar Jul 19 '22 00:07 bergundy

Is there any news on this? we need to change a header per request to include a security token. In java we can do it, but I'm not pretty sure that we can do it in JS SDK

jrpedrianes avatar Nov 03 '22 11:11 jrpedrianes

@jrpedrianes for JS clients, you can set per request headers and deadline. This issue should be closed. See the api reference here: https://typescript.temporal.io/api/classes/client.Connection#withmetadata

bergundy avatar Nov 07 '22 06:11 bergundy

Thanks, @bergundy.

At worker level I see that I can use https://typescript.temporal.io/api/classes/worker.NativeConnection#setmetadata, the method signature is not the same, but it seems that I can call it as many times as I need, in my case to update a security token that a worker needs to send to the temporal server, this token expires, so I need to update it frequently.

jrpedrianes avatar Nov 07 '22 07:11 jrpedrianes