Skip to content

Commit

Permalink
refactor: advance extractFullPath as extractURI
Browse files Browse the repository at this point in the history
  • Loading branch information
gmkim20713 committed Oct 25, 2024
1 parent 40b3509 commit f07d002
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Mono<ResponseEntity<String>> handleGenericException(ServerWebExchange exc
private Mono<ResponseEntity<String>> handleExceptionInternal(ServerWebExchange exchange, Exception exception, HttpStatus status) {
String method = extractMethod(exchange);
String userAgent = extractUserAgent(exchange);
String fullPath = extractFullPath(exchange);
String fullPath = extractURI(exchange);
String originIp = extractOriginIp(exchange);

return extractRequestBody(exchange).flatMap(requestBody -> {
Expand All @@ -99,11 +99,19 @@ private String extractUserAgent(ServerWebExchange exchange) {
return exchange.getRequest().getHeaders().getFirst("User-Agent");
}

private String extractFullPath(ServerWebExchange exchange) {
private String extractURI(ServerWebExchange exchange) {
var request = exchange.getRequest();

String scheme = request.getURI().getScheme();
String host = request.getURI().getHost();
int port = request.getURI().getPort();
String fullPath = request.getURI().getRawPath();
String query = request.getURI().getQuery();
return (query != null && !query.isEmpty()) ? fullPath + "?" + query : fullPath;

String baseUrl = (port != -1) ? host + ":" + port : host;
String uriWithHost = scheme + "://" + baseUrl + fullPath;

return (query != null && !query.isEmpty()) ? uriWithHost + "?" + query : uriWithHost;
}

private String extractOriginIp(ServerWebExchange exchange) {
Expand Down

0 comments on commit f07d002

Please sign in to comment.