1
HelloWorldService.Iface helloService =
        Clients.builder("tbinary+http://127.0.0.1:8080/hello")
               .addHttpHeader("key", "value")
               .build(HelloWorldService.Iface.class);

ServerBuilder sb = Server.builder();
sb.service("/hello", THttpService.of(new HelloServiceImpl()));
sb.http(8080);
Server server = sb.build();
server.start();

How do I handle HTTP headers in the server? THttpService is a final class, so I can not extend it to handle the headers.

trustin
  • 12,231
  • 6
  • 42
  • 52
twogoods
  • 1,646
  • 2
  • 14
  • 21
  • How to get headers, i think a simple interceptor/filter would do the job, but the question is, how to send headers..! – rpajaziti Sep 30 '22 at 15:54

1 Answers1

1

In your HelloServiceImpl class, you can access the current ServiceRequestContext using ServiceRequestContext.current() to access the request headers and other information:

public class HelloServiceImpl implements HelloWorldService.AsyncIface {
    @Override
    public void hello(...) {
        ServiceRequestContext ctx = ServiceRequestContext.current();
        RequestHeaders headers = ctx.request().headers();
        String value = headers.get("key");
        ...
    }
}
trustin
  • 12,231
  • 6
  • 42
  • 52