diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2018-11-19 14:53:00 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2018-11-19 15:00:50 +0100 |
commit | d0af4c555289ca73a3c7119c60d87ecfd6d4676e (patch) | |
tree | 14a1b25555a332693c043eb24414bbc5f9cfd2d3 /jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.java | |
parent | 5a591f4c70ae2ec28a3bc32e32434ccd36694b40 (diff) |
Match uris with implicit port given from scheme
Diffstat (limited to 'jdisc_core/src/main/java/com/yahoo/jdisc/application/UriPattern.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 |