In java there are two ways:
The first and more common way is to install a ServerInterceptor, which has access to the Metadata (a.k.a. headers). Typically the interceptor will create a ForwardingServerCall, which will add the desired headers in the close() method. Since the location of the code that wants to add the header is usually far away from where the interceptor is installed, the interceptor can read the headers out of the Context. When handling an RPC, add the custom headers into the context and the interceptor will apply them.
The second way is more complicated, and that is to use the ServerCall object directly. This is useful if you want more advanced control over the call. Few people use this.