Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class ClientHostInterceptor implements ClientInterceptor {
private String host;
private static Metadata.Key<String> HOST_HEADER =
Metadata.Key.of("Host", Metadata.ASCII_STRING_MARSHALLER);
public ClientHostInterceptor(final String host) { = host;
public String getHost() {
return host;
public void setHost(final String host) { = host;
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(final MethodDescriptor<ReqT, RespT> method,
final CallOptions callOptions, final Channel next) {"Intercepted " + method.getFullMethodName());
ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);
call = new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(call) {
public void start(Listener<RespT> responseListener, Metadata headers) {
if (StringUtils.isNotEmpty(host)) {"Attaching host header. {}", host);
headers.put(HOST_HEADER, host);
super.start(responseListener, headers);
return call;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment