Skip to content

Commit

Permalink
bump to v0.6.3, direct mode enabled by default on h2c ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Eissing committed Jun 1, 2015
1 parent c1766ef commit 5dc893b
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 58 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.6.3
--------------------------------------------------------------------------------
* h2c direct mode is now enabled on http: virtual hosts. It can be disabled
by configuring "H2Direct off" for the base server. This works for clients
with prior knowledge that a http server supports h2c.

v0.6.2
--------------------------------------------------------------------------------
* added "H2Direct (on|off)" as config directive. On a non-TLS host, it enables
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#

AC_PREREQ([2.69])
AC_INIT([mod_h2], [0.6.2], [[email protected]])
AC_INIT([mod_h2], [0.6.3], [[email protected]])

LT_PREREQ([2.2.6])
LT_INIT()
Expand Down
2 changes: 1 addition & 1 deletion mod_h2/h2_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static h2_config defconf = {
-1, /* alt-svc max age */
0, /* serialize headers */
1, /* hack mpm event */
0, /* h2 direct mode */
1, /* h2 direct mode */
};

static void *h2_config_create(apr_pool_t *pool,
Expand Down
51 changes: 42 additions & 9 deletions mod_h2/h2_h2.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const char *h2_protos[] = {
};
apr_size_t h2_protos_len = sizeof(h2_protos)/sizeof(h2_protos[0]);

static const char *H2_MAGIC_TOKEN = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";

/**
* The optional mod_ssl functions we need. We want to compile without using
* mod_ssl's header file.
Expand Down Expand Up @@ -312,7 +314,9 @@ int h2_h2_pre_conn(conn_rec* c, void *arg)
/* Are we using TLS on this connection? */
if (!h2_h2_is_tls(c)) {
if (h2_config_geti(cfg, H2_CONF_DIRECT)) {
h2_ctx_set_protocol(c, "h2c");
/* It might be a direct connection, let
* the connection hook figure it out. */
h2_ctx_get(c, 1);
return DECLINED;
}
else {
Expand Down Expand Up @@ -387,6 +391,8 @@ int h2_h2_process_conn(conn_rec* c)
h2_ctx *ctx = h2_ctx_get(c, 0);

if (ctx) {
h2_config *cfg = h2_config_get(c);

if (h2_ctx_is_task(c)) {
if (!ctx->task_env->serialize_headers) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, c,
Expand All @@ -396,15 +402,42 @@ int h2_h2_process_conn(conn_rec* c)
}
return DECLINED;
}
else if (!h2_ctx_is_negotiated(c)) {
// Let the client/server hellos fly and ALPN call us back.
apr_bucket_brigade* temp_brigade = apr_brigade_create(
c->pool, c->bucket_alloc);
ap_get_brigade(c->input_filters, temp_brigade,
AP_MODE_SPECULATIVE, APR_BLOCK_READ, 1);
apr_brigade_destroy(temp_brigade);
else if (h2_h2_is_tls(c)) {
if (!h2_ctx_is_negotiated(c)) {
apr_bucket_brigade* temp;
// Let the client/server hellos fly and ALPN call us back.
temp = apr_brigade_create(c->pool, c->bucket_alloc);
ap_get_brigade(c->input_filters, temp,
AP_MODE_SPECULATIVE, APR_BLOCK_READ, 1);
apr_brigade_destroy(temp);
}
check_sni_host(c);
}
else if (!h2_ctx_is_negotiated(c)
&& h2_config_geti(cfg, H2_CONF_DIRECT)) {
apr_bucket_brigade* temp;
apr_status_t status;

/* this might be a direct h2c connection, check for the
* magic bytes */
temp = apr_brigade_create(c->pool, c->bucket_alloc);
status = ap_get_brigade(c->input_filters, temp,
AP_MODE_SPECULATIVE, APR_BLOCK_READ, 24);
if (status == APR_SUCCESS) {
if (status == APR_SUCCESS) {
char *s = NULL;
apr_size_t slen;

apr_brigade_pflatten(temp, &s, &slen, c->pool);
if ((slen == 24) && !memcmp(H2_MAGIC_TOKEN, s, 24)) {
h2_ctx_set_protocol(c, "h2c");
}

}
}
apr_brigade_destroy(temp);

}
check_sni_host(c);
}

ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, c, "h2_h2, connection, start");
Expand Down
1 change: 1 addition & 0 deletions mod_h2/h2_h2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,4 @@ static int h2_h2c_upgrade_to(request_rec *r, const char *proto)

return OK;
}

7 changes: 2 additions & 5 deletions sandbox/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ HOST_NAME = test.example.org

HTTP_PORT = 12345
HTTPS_PORT = 12346
HTTP_DIRECT_PORT = 12347

HTTP_AUTH = $(HOST_NAME):$(HTTP_PORT)
HTTPS_AUTH = $(HOST_NAME):$(HTTPS_PORT)
HTTP_DIRECT_AUTH = $(HOST_NAME):$(HTTP_DIRECT_PORT)

GEN = gen
INST_DIR = ../install
Expand Down Expand Up @@ -89,8 +87,8 @@ test: \
@bash test_nghttp_post.sh http://$(HTTP_AUTH)
@bash test_curl_get.sh http://$(HTTP_AUTH)
@bash test_curl_post.sh http://$(HTTP_AUTH)
@bash test_nghttp_get.sh http://$(HTTP_DIRECT_AUTH) direct
@bash test_nghttp_post.sh http://$(HTTP_DIRECT_AUTH) direct
@bash test_nghttp_get.sh http://$(HTTP_AUTH) direct
@bash test_nghttp_post.sh http://$(HTTP_AUTH) direct

################################################################################
# Load Test
Expand Down Expand Up @@ -160,7 +158,6 @@ $(INST_DIR)/.test-setup: \
-e "s,SUBST_SERVER_NAME_SUBST,$(shell hostname -f),g" \
-e "s,SUBST_PORT_HTTP_SUBST,$(HTTP_PORT),g" \
-e "s,SUBST_PORT_HTTPS_SUBST,$(HTTPS_PORT),g" \
-e "s,SUBST_PORT_HTTP_DIRECT_SUBST,$(HTTP_DIRECT_PORT),g" \
-e "s,SUBST_PHP_CGI_SUBST,$(PHP_CGI),g" \
< $$file > $(INST_DIR)/$$file; \
done
Expand Down
1 change: 0 additions & 1 deletion sandbox/test/conf/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ServerName SUBST_SERVER_NAME_SUBST
ServerRoot "SUBST_SERVER_ROOT_SUBST"

Listen SUBST_PORT_HTTP_SUBST
Listen SUBST_PORT_HTTP_DIRECT_SUBST

ServerName localhost

Expand Down
16 changes: 0 additions & 16 deletions sandbox/test/conf/sites/test.example.org.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,3 @@
</IfModule>

</VirtualHost>

<VirtualHost *:SUBST_PORT_HTTP_DIRECT_SUBST>
ServerName test.example.org:SUBST_PORT_HTTP_DIRECT_SUBST
DocumentRoot "SUBST_SERVER_ROOT_SUBST/htdocs/test.example.org"

RewriteEngine on
RewriteRule ^/latest.tar.gz$ /xxx-1.0.2a.tar.gz [R=302,NC]

<IfModule h2_module>
H2Engine on
H2Direct on
</IfModule>

</VirtualHost>


24 changes: 12 additions & 12 deletions sandbox/test/test_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ curl_check_doc() {
DOC="$1"; shift;
MSG="$1"; shift;
ARGS="$@"
echo -n "curl $URL_PREFIX/$DOC: $MSG..."
echo -n " * curl /$DOC: $MSG..."
rm -rf $TMP
mkdir -p $TMP
${CURL} $ARGS $URL_PREFIX/$DOC > $TMP/$DOC || fail
Expand All @@ -62,7 +62,7 @@ nghttp_check_doc() {
DOC="$1"; shift;
MSG="$1"; shift;
ARGS="$@"$ARG_UPGRADE
echo -n "nghttp $URL_PREFIX/$DOC: $MSG..."
echo -n " * nghttp /$DOC: $MSG..."
rm -rf $TMP &&
mkdir -p $TMP &&
${NGHTTP} $ARGS $URL_PREFIX/$DOC > $TMP/$DOC || fail
Expand All @@ -74,7 +74,7 @@ nghttp_check_assets() {
DOC="$1"; shift;
MSG="$1"; shift;
ARGS="$@"$ARG_UPGRADE
echo -n "nghttp $URL_PREFIX/$DOC: $MSG..."
echo -n " * nghttp /$DOC: $MSG..."
rm -rf $TMP &&
mkdir -p $TMP &&
sort > $TMP/reference
Expand All @@ -93,7 +93,7 @@ nghttp_check_content() {
rm -rf $TMP
mkdir -p $TMP
cat > $TMP/expected
echo -n "nghttp $URL_PREFIX/$DOC: $MSG..."
echo -n " * nghttp /$DOC: $MSG..."
${NGHTTP} $ARGS $URL_PREFIX/$DOC > $TMP/$DOC || fail
diff $TMP/expected $TMP/$DOC || fail
echo ok.
Expand All @@ -107,7 +107,7 @@ curl_check_content() {
rm -rf $TMP
mkdir -p $TMP
cat > $TMP/expected
echo -n "curl $URL_PREFIX/$DOC: $MSG..."
echo -n " * curl /$DOC: $MSG..."
${CURL} $ARGS $URL_PREFIX/$DOC > $TMP/$DOC || fail
diff $TMP/expected $TMP/$DOC || fail
echo ok.
Expand All @@ -118,7 +118,7 @@ curl_check_redir() {
REF_DOC="$1"; shift;
MSG="$1"; shift;
ARGS="$@"
echo -n "curl redir $URL_PREFIX/$DOC: $MSG..."
echo -n " * curl redir /$DOC: $MSG..."
rm -rf $TMP
mkdir -p $TMP
${CURL} -D - $ARGS $URL_PREFIX/$DOC >$TMP/redir.out || fail
Expand All @@ -137,7 +137,7 @@ curl_check_necho() {
ARGS="$@"
rm -rf $TMP
mkdir -p $TMP
echo -n "curl $URL_PREFIX/necho.py?count=$COUNT&text=$TEXT..."
echo -n " * curl /necho.py?count=$COUNT&text=$TEXT..."
${CURL} $ARGS -F count="$COUNT" -F text="$TEXT" $URL_PREFIX/necho.py > $TMP/echo || fail
diff $REF $TMP/echo || fail
echo ok.
Expand All @@ -151,7 +151,7 @@ curl_post_file() {
fname="$(basename $FILE)"
rm -rf $TMP
mkdir -p $TMP
echo -n "curl $URL_PREFIX/$DOC: $MSG..."
echo -n " * curl /$DOC: $MSG..."
${CURL} $ARGS --form file=@"$FILE" $URL_PREFIX/$DOC > $TMP/$DOC || fail "error uploading $fname"
${CURL} $ARGS $URL_PREFIX/files/"$fname" > $TMP/data.down || fail "error downloding $fname"
diff $FILE $TMP/data.down || fail
Expand All @@ -166,7 +166,7 @@ curl_post_data() {
fname="$(basename $FILE)"
rm -rf $TMP
mkdir -p $TMP
echo -n "curl $URL_PREFIX/$DOC: $MSG..."
echo -n " * curl /$DOC: $MSG..."
${CURL} $ARGS --form file=@"$FILE" $URL_PREFIX/$DOC > $TMP/$DOC || fail
${CURL} $ARGS $URL_PREFIX/files/"$fname" > $TMP/data.down || fail
diff $FILE $TMP/data.down || fail
Expand All @@ -189,7 +189,7 @@ Content-Type: text/plain
$fname
--DSAJKcd9876--
EOF
echo -n "nghttp $URL_PREFIX/$DOC: rm $fname..."
echo -n " * nghttp /$DOC: rm $fname..."
${NGHTTP} -v $ARGS --data=$TMP/updata -H'Content-Type: multipart/form-data; boundary=DSAJKcd9876' $URL_PREFIX/$DOC > $TMP/$DOC || fail "error removing $fname"
echo ok.
}
Expand Down Expand Up @@ -218,7 +218,7 @@ EOF
echo >> $TMP/updata <<EOF
--DSAJKcd9876--
EOF
echo -n "nghttp $URL_PREFIX/$DOC: $MSG..."
echo -n " * nghttp /$DOC: $MSG..."
${NGHTTP} -v $ARGS --data=$TMP/updata -H'Content-Type: multipart/form-data; boundary=DSAJKcd9876' $URL_PREFIX/$DOC > $TMP/$DOC || fail "error uploading $fname"

${NGHTTP} $ARG_UPGRADE $URL_PREFIX/files/"$fname" > $TMP/data.down || fail "error downloding $fname"
Expand All @@ -231,7 +231,7 @@ curl_check_altsvc() {
EXP_ALT_SVC="$1"; shift;
MSG="$1"; shift;
mkdir -p $TMP
echo -n "curl check alt_svc at $URL_PREFIX/$DOC..."
echo -n " * curl check alt_svc at /$DOC..."
${CURL} "$@" -D $TMP/headers $URL_PREFIX/$DOC > /dev/null || fail
alt_svc="$( fgrep -i 'Alt-Svc: ' $TMP/headers | tr -d "\r\n" )"
alt_svc="${alt_svc#*: }"
Expand Down
2 changes: 1 addition & 1 deletion sandbox/test/test_curl_altsvc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ HTTP_URL="$1"
HTTPS_URL="$2"

source test_common.sh
echo "-- ALT-SVC Tests: $1 --"
echo "curl ALT-SVC on: $@"

URL_PREFIX="$HTTP_URL"
curl_check_altsvc index.html 'h2=":12346"; ma=60, h2c=":12345"; ma=60' "http/1.1" --http1.1
Expand Down
4 changes: 1 addition & 3 deletions sandbox/test/test_curl_get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
#

source test_common.sh
echo "-- GET Tests: $1 --"
echo "curl GET on: $@"

################################################################################
# check content of resources via different methods
################################################################################
echo " - single document -"
curl_check_doc index.html "default"
curl_check_doc index.html "http/1.1" --http1.1
curl_check_doc index.html "http2" --http2
Expand Down Expand Up @@ -53,7 +52,6 @@ SSL_PROTOCOL=
;;
esac

echo " - CGI generated content -"
curl_check_content hello.py "default" <<EOF
$CONTENT
EOF
Expand Down
2 changes: 1 addition & 1 deletion sandbox/test/test_curl_post.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

source test_common.sh
echo "-- POST Tests: $1 --"
echo "curl POST on: $@"

CHR100="012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
"
Expand Down
8 changes: 1 addition & 7 deletions sandbox/test/test_nghttp_get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
#

source test_common.sh
echo "-- GET Tests: $1 --"
echo "nghttp GET on: $@"

################################################################################
# check content of resources via different methods
################################################################################
echo " - single document -"
nghttp_check_doc index.html "default"
nghttp_check_doc 003.html "detault"


################################################################################
# check retrieving multiple resources from inside a page
################################################################################
echo " - multiple resources -"
nghttp_check_assets 001.html "with assets" <<EOF
/001.html 251 200
EOF
Expand Down Expand Up @@ -250,8 +248,6 @@ EOF
################################################################################
# check different window sizes
################################################################################
echo " - different window sizes -"

nghttp_check_assets 003.html "with assets" --window-bits=24 <<EOF
/003.html 316 200
/003/003_img.jpg 88K 200
Expand All @@ -260,8 +256,6 @@ EOF
################################################################################
# check cgi generated content
################################################################################
echo " - CGI generated content -"

case "$URL_PREFIX" in
https:*)
CONTENT="<html>
Expand Down
2 changes: 1 addition & 1 deletion sandbox/test/test_nghttp_post.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

source test_common.sh
echo "-- POST Tests: $1 --"
echo "nghttp POST on: $@"

CHR100="012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
"
Expand Down

0 comments on commit 5dc893b

Please sign in to comment.