#include <apr_strings.h>
#include <httpd.h>
#include <http_core.h>
+#include <http_connection.h>
+#include <http_protocol.h>
#include <http_log.h>
#include "h2_private.h"
#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);
}
/**
#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;
}
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