You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/02/27 09:57:49 UTC
[httpcomponents-core] 02/02: `RequestHandlerRegistry` to resolve
127.0.0.1 as primary host
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
commit 9aac3cb591373ff12f6a2424ac45dbc6cfe19772
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Feb 27 10:44:13 2021 +0100
`RequestHandlerRegistry` to resolve 127.0.0.1 as primary host
---
.../org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java | 7 +++----
.../apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java | 1 +
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java
index 6618806..581d87a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java
@@ -51,6 +51,7 @@ import org.apache.hc.core5.util.Args;
public class RequestHandlerRegistry<T> implements HttpRequestMapper<T> {
private final static String LOCALHOST = "localhost";
+ private final static String IP_127_0_0_1 = "127.0.0.1";
private final String canonicalHostName;
private final Supplier<LookupRegistry<T>> registrySupplier;
@@ -91,10 +92,8 @@ public class RequestHandlerRegistry<T> implements HttpRequestMapper<T> {
}
private LookupRegistry<T> getPatternMatcher(final String hostname) {
- if (hostname == null) {
- return primary;
- }
- if (hostname.equals(canonicalHostName) || hostname.equals(LOCALHOST)) {
+ if (hostname == null ||
+ hostname.equals(canonicalHostName) || hostname.equals(LOCALHOST) || hostname.equals(IP_127_0_0_1)) {
return primary;
}
return virtualMap.get(hostname);
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java b/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java
index 35e43ba..dbbfa71 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java
@@ -82,6 +82,7 @@ public class TestRequestHandlerRegistry {
handlerRegistry.register("myhost", "/test*", "stuff");
Assert.assertEquals("stuff", handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("localhost"), "/test"), context));
Assert.assertEquals("stuff", handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("LocalHost"), "/testabc"), context));
+ Assert.assertEquals("stuff", handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("127.0.0.1"), "/testabc"), context));
}
@Test(expected = MisdirectedRequestException.class)