Skip to content

Instantly share code, notes, and snippets.

@fitzoh
Last active February 10, 2018 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitzoh/266d705448a6821552b96a0462358281 to your computer and use it in GitHub Desktop.
Save fitzoh/266d705448a6821552b96a0462358281 to your computer and use it in GitHub Desktop.
@Component
public class RouteServiceForwardingFilter implements GatewayFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
try {
String forwardUrl = exchange.getRequest().getHeaders().get(FORWARDED_URL).get(0);
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, new URI(forwardUrl));
return chain.filter(exchange);
} catch (URISyntaxException e) {
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
return Mono.empty();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment