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 10:07:39 UTC

[httpcomponents-core] branch 5.0.x updated (5178ff3 -> 6a2e36d)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a change to branch 5.0.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git.


    from 5178ff3  HTTPCORE-659 Race condition in IOSessionImpl when setting event
     new 3ec7c86  `ServerSupport#toStatusCode` to handle MisdirectedRequestException as status 421
     new 6a2e36d  `RequestHandlerRegistry` to resolve 127.0.0.1 as primary host

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/java/org/apache/hc/core5/http/impl/ServerSupport.java | 3 +++
 .../org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java  | 7 +++----
 .../apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java  | 1 +
 3 files changed, 7 insertions(+), 4 deletions(-)


[httpcomponents-core] 02/02: `RequestHandlerRegistry` to resolve 127.0.0.1 as primary host

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch 5.0.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 6a2e36d74fde79f401c09751402ec2f789a525ea
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)


[httpcomponents-core] 01/02: `ServerSupport#toStatusCode` to handle MisdirectedRequestException as status 421

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch 5.0.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 3ec7c86c330891b8426d7eabee77cefe2f248a74
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Feb 27 10:42:49 2021 +0100

    `ServerSupport#toStatusCode` to handle MisdirectedRequestException as status 421
---
 .../src/main/java/org/apache/hc/core5/http/impl/ServerSupport.java     | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/ServerSupport.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/ServerSupport.java
index df6bc12..85b1ee0 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/ServerSupport.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/ServerSupport.java
@@ -32,6 +32,7 @@ import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.MethodNotSupportedException;
+import org.apache.hc.core5.http.MisdirectedRequestException;
 import org.apache.hc.core5.http.NotImplementedException;
 import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.RequestHeaderFieldsTooLargeException;
@@ -73,6 +74,8 @@ public class ServerSupport {
             code = HttpStatus.SC_NOT_IMPLEMENTED;
         } else if (ex instanceof RequestHeaderFieldsTooLargeException) {
             code = HttpStatus.SC_REQUEST_HEADER_FIELDS_TOO_LARGE;
+        } else if (ex instanceof MisdirectedRequestException) {
+            code = HttpStatus.SC_MISDIRECTED_REQUEST;
         } else if (ex instanceof ProtocolException) {
             code = HttpStatus.SC_BAD_REQUEST;
         } else {