Reputation: 11
I would like to create a simple proxy and aggregator server with spring-cloud-gateway. I am using dependency spring-cloud-gateway-webflux
and ProxyExchange to do that. I start the app in localhost and launch it from a browser, however, it returns 404 not found.
If I use spring-cloud-gateway-mvc
instead of spring-cloud-gateway-webflux
, surprising the proxy works and I can browse stackoverflow in my localhost. But I still would like to find out why spring-cloud-gateway-webflux
is not working.
Can anyone help to point out anything that I am missing?
controller:
@RestController
public class RouteController {
@RequestMapping(value="/**", method={ RequestMethod.GET, RequestMethod.POST })
public Mono<ResponseEntity<byte[]>> proxy(ServerHttpRequest request, ServerHttpResponse response, ProxyExchange<byte[]> proxy) throws Exception {
String path = proxy.path("/");
if (request.getMethodValue().startsWith("GET")) {
return proxy.uri("https://stackoverflow.com/" + path).get();
} else {
return proxy.uri("https://stackoverflow.com/" + path).post();
}
}
}
application.yml:
server:
port: 8080
I tried with adding the following to application.yml but it doesn't work.
spring:
cloud:
gateway:
httpclient:
ssl:
useInsecureTrustManager: true
Upvotes: 1
Views: 2842
Reputation: 523
In my situation, it's the problem of http headers. Add the following code, then everything works for me.
proxy.sensitive(HttpHeaders.HOST)
It seems like ProxyExchange will pass down the http request header by default, and in the case of WebClient
, there is no default http header.
Upvotes: 3