Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public List<String> shortcutFieldOrder() {
@Override
public GatewayFilter apply(Config config) {
return new GatewayFilter() {
final UriTemplate uriTemplate = new UriTemplate(
Objects.requireNonNull(config.prefix, "prefix must not be null"));
final String prefix = config.prefix != null ? config.prefix : "";
final UriTemplate uriTemplate = prefix.isEmpty() ? null : new UriTemplate(prefix);

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
Expand All @@ -78,11 +78,16 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest req = exchange.getRequest();
addOriginalRequestUrl(exchange, req.getURI());

Map<String, String> uriVariables = getUriTemplateVariables(exchange);
URI uri = uriTemplate.expand(uriVariables);

String newPath = uri.getRawPath() + req.getURI().getRawPath();
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);
String newPath;
if (uriTemplate != null) {
Map<String, String> uriVariables = getUriTemplateVariables(exchange);
URI uri = uriTemplate.expand(uriVariables);
newPath = uri.getRawPath() + req.getURI().getRawPath();
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);
}
else {
newPath = req.getURI().getRawPath();
}
ServerHttpRequest request = req.mutate().path(newPath).build();

if (log.isTraceEnabled()) {
Expand Down