Skip to content

Commit

Permalink
Normalize the http-root-path at config level
Browse files Browse the repository at this point in the history
I think it's better to make sure it's always consistent. '/' is a bit of
a special case right now and not entirely consistent with the no slash
at the end rule but I think we can live with it.

Fixes #19492
  • Loading branch information
gsmet committed Aug 19, 2021
1 parent 0770982 commit 54aa8c1
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import java.time.Duration;

import org.eclipse.microprofile.config.spi.Converter;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.annotations.ConvertWith;
import io.vertx.core.http.ClientAuth;

@ConfigRoot(name = "http", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
Expand All @@ -14,6 +17,7 @@ public class HttpBuildTimeConfig {
* The HTTP root path. All web content will be served relative to this root path.
*/
@ConfigItem(defaultValue = "/")
@ConvertWith(NormalizeHttpRootPathConverter.class)
public String rootPath;

public AuthConfig auth;
Expand Down Expand Up @@ -43,7 +47,7 @@ public class HttpBuildTimeConfig {
* Non-application endpoints will be served from the specified path.
* * `${quarkus.http.root-path}` -> Setting this path to the same value as HTTP root path disables
* this root path. All extension-provided endpoints will be served from `${quarkus.http.root-path}`.
*
*
* @asciidoclet
*/
@ConfigItem(defaultValue = "q")
Expand All @@ -54,4 +58,29 @@ public class HttpBuildTimeConfig {
*/
@ConfigItem(defaultValue = "30s")
public Duration testTimeout;

public static class NormalizeHttpRootPathConverter implements Converter<String> {

private static final String SLASH = "/";

@Override
public String convert(String value) throws IllegalArgumentException, NullPointerException {
if (value == null) {
return SLASH;
}

value = value.trim();
if (SLASH.equals(value)) {
return value;
}
if (!value.startsWith(SLASH)) {
value = SLASH + value;
}
if (value.endsWith(SLASH)) {
value = value.substring(0, value.length() - 1);
}

return value;
}
}
}

0 comments on commit 54aa8c1

Please sign in to comment.