I noticed that it's currently impossible to use mod_proxy_http2 in
conjunction with mod_rewrite's [P] request proxying:
RewriteEngine On
RewriteRule ^/foo h2c://hostname/bar [P]
mod_proxy_http2 registers on h2:// and h2c:// proxy URLs [1], however,
mod_rewrite needs an update to handle these as absolute URIs. Without
that, the configuration above is going to produce incorrectly rewritten
rewritten URLs, e.g.:
http://www.example.org/h2c://hostname/bar
I attached the patch with a fix for this issue. The second patch adds
the corresponding tests to the mod_http2 testing framework.
[1]
https://mail-archives.apache.org/mod_mbox/httpd-dev/201602.mbox/%[email protected]%3E
Regards,
Evgeny Kotkov
mod_rewrite: Add handling of 'h2' and 'h2c' schemes for mod_proxy_http2.
Index: modules/mappers/mod_rewrite.c
===================================================================
--- modules/mappers/mod_rewrite.c (revision 1743495)
+++ modules/mappers/mod_rewrite.c (working copy)
@@ -568,6 +568,14 @@ static unsigned is_absolute_uri(char *uri, int *su
*sqs = 1;
return 8;
}
+ else if (!ap_casecmpstrn(uri, "2://", 4)) { /* h2:// */
+ *sqs = 1;
+ return 5;
+ }
+ else if (!ap_casecmpstrn(uri, "2c://", 5)) { /* h2c:// */
+ *sqs = 1;
+ return 6;
+ }
break;
case 'l':
Cover the mod_rewrite's [P] proxying in mod_proxy_http2 tests.
Index: Makefile.am
===================================================================
--- Makefile.am (revision 1743495)
+++ Makefile.am (working copy)
@@ -223,6 +223,8 @@ proxytx: \
h2proxytx: \
$(SERVER_DIR)/.test-setup
$(H2LOAD) -c 8 -t 8 -n 1000 -m 1 --npn-list=h2
https://$(HTTPS_AUTH_2)/h2proxy/005.txt
+ $(H2LOAD) -c 8 -t 8 -n 1000 -m 1 --npn-list=h2
https://$(HTTPS_AUTH_2)/h2proxy-rewrite/005.txt
+ $(H2LOAD) -c 8 -t 8 -n 1000 -m 1
http://$(HTTP_AUTH)/h2cproxy-rewrite/005.txt
$(H2LOAD) -c 8 -t 8 -n 1000 -m 1 http://$(HTTP_AUTH)/h2cproxy/005.txt
################################################################################
Index: conf/sites/test.example.org.conf
===================================================================
--- conf/sites/test.example.org.conf (revision 1743495)
+++ conf/sites/test.example.org.conf (working copy)
@@ -135,8 +135,10 @@
<IfModule proxy_http2_module>
ProxyPass "/h2proxy" "balancer://h2-local"
ProxyPassReverse "/h2proxy" "balancer://h2-local"
+ RewriteRule /h2proxy-rewrite(.*)
h2://test.example.org:SUBST_PORT_HTTPS_SUBST$1 [P]
ProxyPass "/h2cproxy" "balancer://h2c-local"
ProxyPassReverse "/h2cproxy" "balancer://h2c-local"
+ RewriteRule /h2cproxy-rewrite(.*)
h2c://test.example.org:SUBST_PORT_HTTP_SUBST$1 [P]
</IfModule>
<IfVersion >= 2.4.19>
@@ -209,8 +211,10 @@
<IfModule proxy_http2_module>
ProxyPass "/h2proxy" "balancer://h2-local"
ProxyPassReverse "/h2proxy" "balancer://h2-local"
+ RewriteRule /h2proxy-rewrite(.*)
h2://test.example.org:SUBST_PORT_HTTPS_SUBST$1 [P]
ProxyPass "/h2cproxy" "balancer://h2c-local"
ProxyPassReverse "/h2cproxy" "balancer://h2c-local"
+ RewriteRule /h2cproxy-rewrite(.*)
h2c://test.example.org:SUBST_PORT_HTTP_SUBST$1 [P]
</IfModule>
<Location "/http2-status">
Index: conf/sites/test2.example.org.conf
===================================================================
--- conf/sites/test2.example.org.conf (revision 1743495)
+++ conf/sites/test2.example.org.conf (working copy)
@@ -10,6 +10,8 @@
DocumentRoot "SUBST_SERVER_ROOT_SUBST/htdocs/test.example.org"
Protocols http/1.1 h2
+ RewriteEngine on
+
SSLEngine on
SSLCertificateFile conf/ssl/test.example.org.pem
SSLCertificateKeyFile conf/ssl/test.example.org.key
@@ -29,8 +31,10 @@
<IfModule proxy_http2_module>
ProxyPass "/h2proxy" "balancer://h2-local"
ProxyPassReverse "/h2proxy" "balancer://h2-local"
+ RewriteRule /h2proxy-rewrite(.*)
h2://test.example.org:SUBST_PORT_HTTPS_SUBST$1 [P]
ProxyPass "/h2cproxy" "balancer://h2c-local"
ProxyPassReverse "/h2cproxy" "balancer://h2c-local"
+ RewriteRule /h2cproxy-rewrite(.*)
h2c://test.example.org:SUBST_PORT_HTTP_SUBST$1 [P]
</IfModule>
</VirtualHost>
@@ -59,8 +63,10 @@
<IfModule proxy_http2_module>
ProxyPass "/h2proxy" "balancer://h2-local"
ProxyPassReverse "/h2proxy" "balancer://h2-local"
+ RewriteRule /h2proxy-rewrite(.*)
h2://test.example.org:SUBST_PORT_HTTPS_SUBST$1 [P]
ProxyPass "/h2cproxy" "balancer://h2c-local"
ProxyPassReverse "/h2cproxy" "balancer://h2c-local"
+ RewriteRule /h2cproxy-rewrite(.*)
h2c://test.example.org:SUBST_PORT_HTTP_SUBST$1 [P]
</IfModule>
</VirtualHost>
Index: test/test_common.sh
===================================================================
--- test/test_common.sh (revision 1743495)
+++ test/test_common.sh (working copy)
@@ -91,13 +91,13 @@ if min_version 2.4.19; then
EXP_H1_HTTP2=""
EXP_H2_H2PUSH=""
;;
- */h2proxy)
+ */h2proxy|*/h2proxy-rewrite)
EXP_HTTP2="on"
EXP_H2PUSH="off"
EXP_H1_HTTP2="${EXP_HTTP2}"
EXP_H1_H2PUSH="${EXP_H2PUSH}"
;;
- */h2cproxy)
+ */h2cproxy|*/h2cproxy-rewrite)
EXP_HTTP2="on"
EXP_H2PUSH="off"
EXP_H1_HTTP2="${EXP_HTTP2}"
@@ -116,13 +116,13 @@ case "$URL_PREFIX" in
*/proxy|*/rewrite)
EXP_PROTOCOL="HTTP/1.1"
;;
- */h2proxy)
+ */h2proxy|*/h2proxy-rewrite)
EXP_HTTPS="on"
EXP_PROTOCOL="${HTTP2_PROTOCOL}"
EXP_H1_PROTOCOL="${EXP_PROTOCOL}"
EXP_SSL_PROTOCOL="TLSv1.2"
;;
- */h2cproxy)
+ */h2cproxy|*/h2cproxy-rewrite)
EXP_HTTPS=""
EXP_SSL_PROTOCOL=""
EXP_PROTOCOL="${HTTP2_PROTOCOL}"
Index: test/test_h2proxy_load.sh
===================================================================
--- test/test_h2proxy_load.sh (revision 1743495)
+++ test/test_h2proxy_load.sh (working copy)
@@ -44,7 +44,7 @@ EOF
load_suite() {
URL_PREFIX="$1"; shift
- local n=10000
+ local n="$1"; shift
echo "loading $URL_PREFIX $n requests"
load_run " 1 connection " $n -c 1 -t 1 -m 100
@@ -58,7 +58,9 @@ load_suite() {
if min_version 2.5.0; then
-load_suite $HTTPS_AUTH_2/h2proxy
-load_suite $HTTPS_AUTH_2/h2cproxy
+load_suite $HTTPS_AUTH_2/h2proxy 10000
+load_suite $HTTPS_AUTH_2/h2proxy-rewrite 1000
+load_suite $HTTPS_AUTH_2/h2cproxy 10000
+load_suite $HTTPS_AUTH_2/h2cproxy-rewrite 1000
fi
Index: test/test_proxy.sh
===================================================================
--- test/test_proxy.sh (revision 1743495)
+++ test/test_proxy.sh (working copy)
@@ -40,13 +40,23 @@ $URL_PREFIX/h2proxy/004/gophertiles_002.jpg
$URL_PREFIX/h2proxy/004/gophertiles_003.jpg
$URL_PREFIX/h2proxy/004/gophertiles_004.jpg
$URL_PREFIX/h2proxy/004/gophertiles_005.jpg
+$URL_PREFIX/h2proxy-rewrite/004.html
+$URL_PREFIX/h2proxy-rewrite/004/gophertiles_002.jpg
+$URL_PREFIX/h2proxy-rewrite/004/gophertiles_003.jpg
+$URL_PREFIX/h2proxy-rewrite/004/gophertiles_004.jpg
+$URL_PREFIX/h2proxy-rewrite/004/gophertiles_005.jpg
$URL_PREFIX/h2cproxy/004.html
$URL_PREFIX/h2cproxy/004/gophertiles_002.jpg
$URL_PREFIX/h2cproxy/004/gophertiles_003.jpg
$URL_PREFIX/h2cproxy/004/gophertiles_004.jpg
$URL_PREFIX/h2cproxy/004/gophertiles_005.jpg
+$URL_PREFIX/h2cproxy-rewrite/004.html
+$URL_PREFIX/h2cproxy-rewrite/004/gophertiles_002.jpg
+$URL_PREFIX/h2cproxy-rewrite/004/gophertiles_003.jpg
+$URL_PREFIX/h2cproxy-rewrite/004/gophertiles_004.jpg
+$URL_PREFIX/h2cproxy-rewrite/004/gophertiles_005.jpg
EOF
- h2load_check_requests "loading from 2 proxied locations" \
+ h2load_check_requests "loading from 4 proxied locations" \
-i $TMP/urls.txt -n 10000 -c 1 -t 1 -m 100 <<EOF
requests: 10000 total, 10000 started, 10000 done, 10000 succeeded, 0 failed, 0
errored, 0 timeout
EOF
@@ -54,10 +64,18 @@ EOF
if min_version 2.5.0; then
+$SHELL "$TEST_DIR"/test_nghttp_get.sh $HTTPS_AUTH/h2cproxy-rewrite
&&
+$SHELL "$TEST_DIR"/test_nghttp_post.sh $HTTPS_AUTH/h2cproxy-rewrite
&&
+$SHELL "$TEST_DIR"/test_curl_get.sh $HTTPS_AUTH/h2cproxy-rewrite
&&
+$SHELL "$TEST_DIR"/test_curl_post.sh $HTTPS_AUTH/h2cproxy-rewrite
&&
$SHELL "$TEST_DIR"/test_nghttp_get.sh $HTTPS_AUTH/h2cproxy
&&
$SHELL "$TEST_DIR"/test_nghttp_post.sh $HTTPS_AUTH/h2cproxy
&&
$SHELL "$TEST_DIR"/test_curl_get.sh $HTTPS_AUTH/h2cproxy
&&
$SHELL "$TEST_DIR"/test_curl_post.sh $HTTPS_AUTH/h2cproxy
&&
+$SHELL "$TEST_DIR"/test_nghttp_get.sh $HTTPS_AUTH/h2proxy-rewrite
&&
+$SHELL "$TEST_DIR"/test_nghttp_post.sh $HTTPS_AUTH/h2proxy-rewrite
&&
+$SHELL "$TEST_DIR"/test_curl_get.sh $HTTPS_AUTH/h2proxy-rewrite
&&
+$SHELL "$TEST_DIR"/test_curl_post.sh $HTTPS_AUTH/h2proxy-rewrite
&&
$SHELL "$TEST_DIR"/test_nghttp_get.sh $HTTPS_AUTH/h2proxy
&&
$SHELL "$TEST_DIR"/test_nghttp_post.sh $HTTPS_AUTH/h2proxy
&&
$SHELL "$TEST_DIR"/test_curl_get.sh $HTTPS_AUTH/h2proxy
&&