diff options
Diffstat (limited to 'jdisc_core/src/main/java')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java | 17 |
1 files changed, 16 insertions, 1 deletions
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; * </ul> * * @author Simon Thoresen Hult + * @author bjorncs */ public class UriPattern implements Comparable<UriPattern> { @@ -86,7 +87,7 @@ public class UriPattern implements Comparable<UriPattern> { 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<UriPattern> { 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; + } + } + /** * <p>This class holds the result of a {@link UriPattern#match(URI)} operation. It contains methods to inspect the * groups captured during matching, where a <em>group</em> is defined as a sequence of characters matches by a |