Skip to content

Commit

Permalink
Refactor support for URI path prefix modification
Browse files Browse the repository at this point in the history
  • Loading branch information
big-cir committed Dec 29, 2024
1 parent bfb240d commit 6beb13b
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,25 @@ public byte[] modifyContent(byte[] content, MediaType contentType) {
private String modify(String input) {
List<String> replacements = Arrays.asList(this.scheme, this.host,
StringUtils.hasText(this.port) ? ":" + this.port : this.port,
this.pathPrefix);
this.pathPrefix == null ? "" : this.pathPrefix.startsWith("/") ? this.pathPrefix : "/" + this.pathPrefix);

int previous = 0;

Matcher matcher = SCHEME_HOST_PORT_PATTERN.matcher(input);
StringBuilder builder = new StringBuilder();
while (matcher.find()) {
for (int i = 1; i <= matcher.groupCount(); i++) {
int matcherGroupCount = matcher.groupCount();
for (int i = 1; i <= matcherGroupCount; i++) {
if (matcher.start(i) >= 0) {
builder.append(input, previous, matcher.start(i));
}
if (matcher.start(i) >= 0) {
previous = matcher.end(i);
}
builder.append(getReplacement(matcher.group(i), replacements.get(i - 1)));
if (i == matcherGroupCount) {
builder.append(replacements.get(i));
}
}
}

Expand Down

0 comments on commit 6beb13b

Please sign in to comment.