Does Wire have an equivalent to io.grpc.Metadata and MetadataUtils for attaching headers to calls dynamically?

369 views Asked by At

For instance, attaching Metadata to a stub as headers would look something like

            val stub = MetadataUtils.attachHeaders(
                    SomeCoroutineGrpc.newStubWithContext(channel),
                    metadata.toMetadata()
            )

and I could make a call using the stub with attached headers, such as login credentials. How would I achieve this with Wire? Would I have to construct a new OkHttp client with interceptors to attach the appropriate headers each time, thus requiring me to create a new instance of my Wire Grpc client, and so defeat the purpose of Channel reuse and Multiplexing?

1

There are 1 answers

0
Jesse Wilson On BEST ANSWER

Thanks for opening the tracking bug for this.

If you use OkHttpClient.newBuilder(), you can add interceptors while retaining connection reuse. That method shares the same connection pool with the client it was created from.

We need to implement support for this in Wire. Let's discuss API and timeline on the tracking bug.