From 7689d7c1e15ab294b7b91d3040b57335bae1228c Mon Sep 17 00:00:00 2001 From: joohyun Date: Sun, 28 Apr 2024 19:18:53 +0900 Subject: [PATCH] =?UTF-8?q?feature:#12=20Gateway=EC=97=90=EC=84=9C=20Reiss?= =?UTF-8?q?ue=20=EC=A7=84=ED=96=89=EC=8B=9C=20request=20parameter=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/GlobalHttpReIssueFilter.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/t3t/apigateway/filter/GlobalHttpReIssueFilter.java b/src/main/java/com/t3t/apigateway/filter/GlobalHttpReIssueFilter.java index 5342a17..0497c12 100644 --- a/src/main/java/com/t3t/apigateway/filter/GlobalHttpReIssueFilter.java +++ b/src/main/java/com/t3t/apigateway/filter/GlobalHttpReIssueFilter.java @@ -17,7 +17,6 @@ import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; -import java.net.URI; import java.util.Objects; /** @@ -66,7 +65,13 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { WebClient webClient = WebClient.create(); Mono responseMono = webClient.post() // 추후 profile별 url로 전송되게 해야함 - .uri("http://localhost:8084/refresh") + .uri(uriBuilder -> uriBuilder + .scheme("http") + .host("localhost") + .port(8084) + .path("/refresh") + .query(exchange.getRequest().getURI().getQuery()) // 이전 요청의 쿼리 파라미터 추가 + .build()) .header(HttpHeaders.AUTHORIZATION, "Bearer " + access) .exchange(); @@ -75,7 +80,7 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { String receivedNewToken = resp.headers().asHttpHeaders().getFirst(HttpHeaders.AUTHORIZATION); ServerHttpRequest originalReq = finalExchange.getRequest().mutate() - .uri(URI.create(originalUrl)) + .uri(finalExchange.getRequest().getURI()) .header(HttpHeaders.AUTHORIZATION, receivedNewToken) .build(); @@ -92,7 +97,13 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { WebClient webClient = WebClient.create(); Mono responseMono = webClient.post() - .uri("http://localhost:8084/refresh") + .uri(uriBuilder -> uriBuilder + .scheme("http") + .host("localhost") + .port(8084) + .path("/refresh") + .query(exchange.getRequest().getURI().getQuery()) // 이전 요청의 쿼리 파라미터 추가 + .build()) .header(HttpHeaders.AUTHORIZATION, "Bearer " + access) .exchange(); @@ -101,7 +112,7 @@ public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { String receivedNewToken = resp.headers().asHttpHeaders().getFirst(HttpHeaders.AUTHORIZATION); ServerHttpRequest originalReq = finalExchange.getRequest().mutate() - .uri(URI.create(originalUrl)) + .uri(finalExchange.getRequest().getURI()) .header(HttpHeaders.AUTHORIZATION, receivedNewToken) .build();