Backport of:

From a0521d289ae14e4ac004811dc1ef91b3e118a2f6 Mon Sep 17 00:00:00 2001
From: Stefan Eissing <icing@apache.org>
Date: Thu, 16 Dec 2021 11:23:49 +0000
Subject: [PATCH] Merge of r1895981,r1895986 from trunk:

  *) mod_proxy: Don't prevent forwarding URIs w/ no hostname.
                (fix for r1895955 already in 2.4.x)



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1896044 13f79535-47bb-0310-9956-ffa450edef68
---
 modules/proxy/mod_proxy.c  |  5 +++--
 modules/proxy/mod_proxy.h  |  1 +
 modules/proxy/proxy_util.c | 22 ++++++++++++----------
 3 files changed, 16 insertions(+), 12 deletions(-)

--- a/modules/proxy/mod_proxy.c
+++ b/modules/proxy/mod_proxy.c
@@ -556,9 +556,10 @@ static int proxy_detect(request_rec *r)
 
     /* Ick... msvc (perhaps others) promotes ternary short results to int */
 
-    if (conf->req && r->parsed_uri.scheme && r->parsed_uri.hostname) {
+    if (conf->req && r->parsed_uri.scheme) {
         /* but it might be something vhosted */
-        if (strcasecmp(r->parsed_uri.scheme, ap_http_scheme(r)) != 0
+        if (!r->parsed_uri.hostname
+            || strcasecmp(r->parsed_uri.scheme, ap_http_scheme(r)) != 0
             || !ap_matches_request_vhost(r, r->parsed_uri.hostname,
                                          (apr_port_t)(r->parsed_uri.port_str
                                                       ? r->parsed_uri.port
--- a/modules/proxy/proxy_util.c
+++ b/modules/proxy/proxy_util.c
@@ -1989,22 +1989,21 @@ PROXY_DECLARE(int) ap_proxy_pre_request(
 
     access_status = proxy_run_pre_request(worker, balancer, r, conf, url);
     if (access_status == DECLINED && *balancer == NULL) {
+        const int forward = (r->proxyreq == PROXYREQ_PROXY);
         *worker = ap_proxy_get_worker(r->pool, NULL, conf, *url);
         if (*worker) {
             ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
                           "%s: found worker %s for %s",
                           (*worker)->s->scheme, (*worker)->s->name, *url);
-            *balancer = NULL;
-            if (!fix_uds_filename(r, url)) {
+            if (!forward && !fix_uds_filename(r, url)) {
                 return HTTP_INTERNAL_SERVER_ERROR;
             }
             access_status = OK;
         }
-        else if (r->proxyreq == PROXYREQ_PROXY) {
+        else if (forward) {
             if (conf->forward) {
                 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
                               "*: found forward proxy worker for %s", *url);
-                *balancer = NULL;
                 *worker = conf->forward;
                 access_status = OK;
                 /*
@@ -2018,8 +2017,8 @@ PROXY_DECLARE(int) ap_proxy_pre_request(
         else if (r->proxyreq == PROXYREQ_REVERSE) {
             if (conf->reverse) {
                 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
-                              "*: using default reverse proxy worker for %s (no keepalive)", *url);
-                *balancer = NULL;
+                              "*: using default reverse proxy worker for %s "
+                              "(no keepalive)", *url);
                 *worker = conf->reverse;
                 access_status = OK;
                 /*
