application中的配置(ssl证书放在resources下)
#配置https
server.ssl.enabled=true
server.ssl.key-store-password=******
server.ssl.key-store=classpath:server.jks
server.ssl.key-store-type=JKS
spring.cloud.gateway.httpclient.ssl.useInsecureTrustManager=true
spring.cloud.gateway.httpclient.ssl.handshake-timeout-millis=10000
spring.cloud.gateway.httpclient.ssl.close-notify-flush-timeout-millis=3000
spring.cloud.gateway.httpclient.ssl.close-notify-read-timeout-millis=0

在AuthSignatureFilter过滤的filter(ServerWebExchange exchange, GatewayFilterChain chain)中配置路由转发,然后加入upgradeConnection方法


 1.Object uriObj = exchange.getAttributes().get(GATEWAY_REQUEST_URL_ATTR);
	if (uriObj != null) {
		URI uri = (URI) uriObj;
		uri = this.upgradeConnection(uri, "http");
		exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);
	}


 2. private URI upgradeConnection(URI uri, String scheme) {
		UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUri(uri).scheme(scheme);
		if (uri.getRawQuery() != null) {
			uriComponentsBuilder.replaceQuery(uri.getRawQuery().replace("+", "%20"));
		}
		return uriComponentsBuilder.build(true).toUri();
	}

其他服务需要用到https那么也必须在其application中做相应的配置,过滤转发不用配置

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐