You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/02/08 08:52:49 UTC

[tomcat] branch 9.0.x updated: Fix HTTP_HOST for HTTP/2

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

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 800c760  Fix HTTP_HOST for HTTP/2
800c760 is described below

commit 800c76037fe348e40db893551f9ca226e7bfa866
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Sat Feb 8 08:45:46 2020 +0000

    Fix HTTP_HOST for HTTP/2
---
 java/org/apache/catalina/valves/rewrite/ResolverImpl.java | 13 +++++--------
 webapps/docs/changelog.xml                                |  6 ++++++
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/catalina/valves/rewrite/ResolverImpl.java b/java/org/apache/catalina/valves/rewrite/ResolverImpl.java
index db97221..a71d64c 100644
--- a/java/org/apache/catalina/valves/rewrite/ResolverImpl.java
+++ b/java/org/apache/catalina/valves/rewrite/ResolverImpl.java
@@ -49,14 +49,11 @@ public class ResolverImpl extends Resolver {
         } else if (key.equals("HTTP_FORWARDED")) {
             return request.getHeader("forwarded");
         } else if (key.equals("HTTP_HOST")) {
-            String host = request.getHeader("host");
-            if (host != null) {
-                int index = host.indexOf(':');
-                if (index != -1) {
-                    host = host.substring(0, index);
-                }
-            }
-            return host;
+            // Don't look directly at the host header to handle:
+            // - Host name in HTTP/1.1 request line
+            // - HTTP/0.9 & HTTP/1.0 requests
+            // - HTTP/2 :authority pseudo header
+            return request.getServerName();
         } else if (key.equals("HTTP_PROXY_CONNECTION")) {
             return request.getHeader("proxy-connection");
         } else if (key.equals("HTTP_ACCEPT")) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 65ad524..817686d 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -50,6 +50,12 @@
       <fix>
         Store config compatibility with HostWebXmlCacheCleaner listener. (remm)
       </fix>
+      <fix>
+        Modify the <code>RewriteValve</code> to use
+        <code>ServletRequest.getServerName()</code> to populate the
+        <code>HTTP_HOST</code> variable rather than extracting it from the
+        <code>Host</code> header as this allows HTTP/2 to be supported. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org