From de15a34dc8950c65d4e7d50119d2be1364b57a60 Mon Sep 17 00:00:00 2001
From: Jean-Frederic Clere
Date: Tue, 11 Jul 2017 11:41:44 +0000
Subject: [PATCH] Add logic to read the Upgrade header and use it in the
response. Use we you are proxying to a server that has multiple upgrade on
the same IP/Port. PR 61142
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1801594 13f79535-47bb-0310-9956-ffa450edef68
---
docs/manual/mod/mod_proxy_wstunnel.xml | 4 +++-
modules/proxy/mod_proxy_wstunnel.c | 7 ++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/docs/manual/mod/mod_proxy_wstunnel.xml b/docs/manual/mod/mod_proxy_wstunnel.xml
index 41afed0548..111adfc81e 100644
--- a/docs/manual/mod/mod_proxy_wstunnel.xml
+++ b/docs/manual/mod/mod_proxy_wstunnel.xml
@@ -55,7 +55,9 @@ ProxyPass "/wss2/" "wss://echo.websocket.org/"
In fact the module can be used to upgrade to other protocols, you can set the upgrade
parameter in the ProxyPass
directive to allow the module to accept other protocol.
-NONE means you bypass the check for the header but still upgrade to WebSocket.
+NONE means you bypass the check for the header but still upgrade to WebSocket.
+ANY means that Upgrade
will read in the request headers and use
+in the response Upgrade
mod_proxy
diff --git a/modules/proxy/mod_proxy_wstunnel.c b/modules/proxy/mod_proxy_wstunnel.c
index 8c0e06c195..5819ad65b9 100644
--- a/modules/proxy/mod_proxy_wstunnel.c
+++ b/modules/proxy/mod_proxy_wstunnel.c
@@ -329,6 +329,10 @@ static int proxy_wstunnel_request(apr_pool_t *p, request_rec *r,
if (ap_cstr_casecmp(upgrade_method, "NONE") == 0) {
buf = apr_pstrdup(p, "Upgrade: WebSocket" CRLF "Connection: Upgrade" CRLF CRLF);
+ } else if (ap_cstr_casecmp(upgrade_method, "ANY") == 0) {
+ const char *upgrade;
+ upgrade = apr_table_get(r->headers_in, "Upgrade");
+ buf = apr_pstrcat(p, "Upgrade: ", upgrade, CRLF "Connection: Upgrade" CRLF CRLF, NULL);
} else {
buf = apr_pstrcat(p, "Upgrade: ", upgrade_method, CRLF "Connection: Upgrade" CRLF CRLF, NULL);
}
@@ -473,7 +477,8 @@ static int proxy_wstunnel_handler(request_rec *r, proxy_worker *worker,
if (ap_cstr_casecmp(upgrade_method, "NONE") != 0) {
const char *upgrade;
upgrade = apr_table_get(r->headers_in, "Upgrade");
- if (!upgrade || ap_cstr_casecmp(upgrade, upgrade_method) != 0) {
+ if (!upgrade || (ap_cstr_casecmp(upgrade, upgrade_method) != 0 &&
+ ap_cstr_casecmp(upgrade_method, "ANY") !=0)) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02900)
"declining URL %s (not %s, Upgrade: header is %s)",
url, upgrade_method, upgrade ? upgrade : "missing");
--
2.40.0