Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Headers to the CoroutineContext #109

Open
AliLozano opened this issue Feb 27, 2020 · 2 comments
Open

Add Headers to the CoroutineContext #109

AliLozano opened this issue Feb 27, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@AliLozano
Copy link

AliLozano commented Feb 27, 2020

Currently only GrpcContext is added, but it could be useful to have headers/metadata object to the context, the Grpc java need always have a interceptor to pass headers to GrpcContext, but I don't understand why?, If there are not a reason, I suggest that it can be put in CoroutineContext.

@marcoferrer marcoferrer added the enhancement New feature or request label Mar 13, 2020
@marcoferrer
Copy link
Owner

Providing this by default I think would be too prescriptive, but I don't think its worth including an interceptor implementation with the standard library to allow users to explicitly opt into the functionality.

@AliLozano
Copy link
Author

AliLozano commented Mar 14, 2020

What do you mean with "too prescriptive", I don't think it be a bad idea and could be very useful.

Here is the interceptor that I currently use, but I think I could be better if it is transparent, also I think that koto should implement a way to handle suspendible interceptors(maybe a scope overridable), because we don't have coroutine context in grpc interceptors, but this is another thing 🙊.

val GRPC_CONTEXT_METADATA = Context.key<Metadata>("GRPC_CONTEXT_METADATA")

class MetaToGrpcContextInterceptor : ServerInterceptor {
    override fun <ReqT, RespT> interceptCall(call: ServerCall<ReqT, RespT>,
                                             headers: Metadata,
                                             next: ServerCallHandler<ReqT, RespT>): ServerCall.Listener<ReqT> {
        val ctx = Context.current().withValue(GRPC_CONTEXT_METADATA, headers)
        return Contexts.interceptCall(ctx, call, headers, next)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants