Skip to content

Commit

Permalink
Resolve baseUrl to String vs temporary URI
Browse files Browse the repository at this point in the history
Along the lines of what was suggested in #30047.

Closes gh-30062
  • Loading branch information
rstoyanchev committed Mar 2, 2023
1 parent 682a4d5 commit 9624ea3
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,15 @@ private static URI initUri(HttpServerRequest request) throws URISyntaxException
return new URI(resolveBaseUrl(request) + resolveRequestUri(request));
}

private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException {
String scheme = getScheme(request);
private static String resolveBaseUrl(HttpServerRequest request) {
String scheme = request.scheme();
int port = request.hostPort();
return ((scheme.equals("http") || scheme.equals("ws")) && (port != 80)) ||
((scheme.equals("https") || scheme.equals("wss")) && (port != 443)) ?
new URI(scheme, null, request.hostName(), port, null, null, null) :
new URI(scheme, request.hostName(), null, null);
return scheme + "://" + request.hostName() + (usePort(scheme, port) ? ":" + port : "");
}

private static String getScheme(HttpServerRequest request) {
return request.scheme();
private static boolean usePort(String scheme, int port) {
return ((scheme.equals("http") || scheme.equals("ws")) && (port != 80)) ||
((scheme.equals("https") || scheme.equals("wss")) && (port != 443));
}

private static String resolveRequestUri(HttpServerRequest request) {
Expand Down

0 comments on commit 9624ea3

Please sign in to comment.