Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

HTTP Gateway Core

The base module of HTTP Gateway that enables to proxy incoming downstream requests to upstream services.

Other modules are needed to add the notions of clients and services, or to enables reading configuration files.

The Gateway Core module is usable as it is though, for example to proxy all incoming requests to a single host, it is possible to do:

HttpGatewayUpstreamClient httpGatewayUpstreamClient = new HttpGatewayUpstreamClient();
HttpGateway httpGateway = HttpGateway.start(new HttpGatewayConfiguration(
    HTTP_GATEWAY_PORT,
    HttpGatewayRouterConfiguration.asyncRouting(request -> {
        HttpGatewayUpstreamRequest upstreamRequest = httpGatewayUpstreamClient
            .prepareRequest(request)
            .withUrl("http://remote-host.com" + request.path());
        CompletableFuture<HttpGatewayUpstreamResponse> upstreamFutureResponse = httpGatewayUpstreamClient.executeUpstreamRequest(upstreamRequest);
        return upstreamFutureResponse.thenApply(upstreamResponse -> {
            if (upstreamResponse.getStatusCode() > HttpResponseStatus.INTERNAL_SERVER_ERROR.code()) {
                // Do not forward the response body if the upstream server returns an internal error
                // => this enables to avoid forwarding sensitive information
                upstreamResponse.setPublisher(null);
            }

            return HttpGatewayDownstreamResponses.buildResult(upstreamResponse);
        });
    })
));

Some more samples are available in the test file HttpGatewayTest.