From 2db3ea7e7f2674988384d5103c19dae744fc060d Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Mon, 17 Aug 2015 14:02:07 +0000 Subject: [PATCH] announcing Alt-Svc only on first request per connection, using handler independent hook git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1696279 13f79535-47bb-0310-9956-ffa450edef68 --- modules/http2/h2_alt_svc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/http2/h2_alt_svc.c b/modules/http2/h2_alt_svc.c index 2eaab12791..9db208149e 100644 --- a/modules/http2/h2_alt_svc.c +++ b/modules/http2/h2_alt_svc.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include "h2_private.h" @@ -25,11 +27,11 @@ #include "h2_h2.h" #include "h2_util.h" -static int h2_alt_svc_request_handler(request_rec *r); +static int h2_alt_svc_handler(request_rec *r); void h2_alt_svc_register_hooks(void) { - ap_hook_handler(h2_alt_svc_request_handler, NULL, NULL, APR_HOOK_LAST); + ap_hook_post_read_request(h2_alt_svc_handler, NULL, NULL, APR_HOOK_MIDDLE); } /** @@ -69,12 +71,18 @@ h2_alt_svc *h2_alt_svc_parse(const char *s, apr_pool_t *pool) { #define h2_alt_svc_IDX(list, i) ((h2_alt_svc**)(list)->elts)[i] -static int h2_alt_svc_request_handler(request_rec *r) +static int h2_alt_svc_handler(request_rec *r) { - h2_ctx *ctx = h2_ctx_rget(r); + h2_ctx *ctx; h2_config *cfg; int i; + if (r->connection->keepalives > 0) { + /* Only announce Alt-Svc on the first response */ + return DECLINED; + } + + ctx = h2_ctx_rget(r); if (h2_ctx_is_active(ctx) || h2_ctx_is_task(ctx)) { return DECLINED; } @@ -82,7 +90,7 @@ static int h2_alt_svc_request_handler(request_rec *r) cfg = h2_config_rget(r); if (r->hostname && cfg && cfg->alt_svcs && cfg->alt_svcs->nelts > 0) { const char *alt_svc_used = apr_table_get(r->headers_in, "Alt-Svc-Used"); - if (!alt_svc_used /*|| (alt_svc_used[0] == '0')*/) { + if (!alt_svc_used) { /* We have alt-svcs defined and client is not already using * one, announce the services that were configured and match. * The security of this connection determines if we allow -- 2.40.0