From d0af4c555289ca73a3c7119c60d87ecfd6d4676e Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Mon, 19 Nov 2018 14:53:00 +0100 Subject: Match uris with implicit port given from scheme --- .../java/com/yahoo/jdisc/application/UriPattern.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java') diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java index 3481e0612fc..89cb6412181 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java @@ -25,6 +25,7 @@ import java.util.regex.Pattern; * * * @author Simon Thoresen Hult + * @author bjorncs */ public class UriPattern implements Comparable { @@ -86,7 +87,7 @@ public class UriPattern implements Comparable { if (pathMatch == null) { return null; } - if (port > 0 && port != uri.getPort()) { + if (port > 0 && port != resolvePortComponent(uri)) { return null; } // Match scheme before host because it has a higher chance of differing (e.g. http versus https) @@ -157,6 +158,20 @@ public class UriPattern implements Comparable { return Integer.parseInt(str); } + private static int resolvePortComponent(URI uri) { + int rawPort = uri.getPort(); + return rawPort != -1 ? rawPort : resolvePortFromScheme(uri.getScheme()); + } + + private static int resolvePortFromScheme(String scheme) { + if (scheme == null) return -1; + switch (scheme) { + case "http": return 80; + case "https": return 443; + default: return -1; + } + } + /** *

This class holds the result of a {@link UriPattern#match(URI)} operation. It contains methods to inspect the * groups captured during matching, where a group is defined as a sequence of characters matches by a -- cgit v1.2.3