httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ic...@apache.org
Subject svn commit: r1725301 [6/6] - in /httpd/httpd/branches/2.4.x: ./ docs/manual/mod/ modules/http2/
Date Mon, 18 Jan 2016 16:22:58 GMT
Modified: httpd/httpd/branches/2.4.x/modules/http2/mod_http2.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/http2/mod_http2.c?rev=1725301&r1=1725300&r2=1725301&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/http2/mod_http2.c (original)
+++ httpd/httpd/branches/2.4.x/modules/http2/mod_http2.c Mon Jan 18 16:22:57 2016
@@ -18,19 +18,24 @@
 #include <apr_want.h>
 
 #include <httpd.h>
+#include <http_protocol.h>
+#include <http_request.h>
 #include <http_log.h>
 
-#include "mod_h2.h"
+#include "mod_http2.h"
 
 #include <nghttp2/nghttp2.h>
 #include "h2_stream.h"
 #include "h2_alt_svc.h"
 #include "h2_conn.h"
+#include "h2_filter.h"
 #include "h2_task.h"
 #include "h2_session.h"
 #include "h2_config.h"
 #include "h2_ctx.h"
 #include "h2_h2.h"
+#include "h2_push.h"
+#include "h2_request.h"
 #include "h2_switch.h"
 #include "h2_version.h"
 
@@ -47,6 +52,8 @@ AP_DECLARE_MODULE(http2) = {
     h2_hooks
 };
 
+static int h2_h2_fixups(request_rec *r);
+
 /* The module initialization. Called once as apache hook, before any multi
  * processing (threaded or not) happens. It is typically at least called twice, 
  * see
@@ -106,6 +113,10 @@ static int h2_post_config(apr_pool_t *p,
     return status;
 }
 
+static char *http2_var_lookup(apr_pool_t *, server_rec *,
+                         conn_rec *, request_rec *, char *name);
+static int http2_is_h2(conn_rec *);
+
 /* Runs once per created child process. Perform any process 
  * related initionalization here.
  */
@@ -117,6 +128,9 @@ static void h2_child_init(apr_pool_t *po
         ap_log_error(APLOG_MARK, APLOG_ERR, status, s,
                      APLOGNO(02949) "initializing connection handling");
     }
+    
+    APR_REGISTER_OPTIONAL_FN(http2_is_h2);
+    APR_REGISTER_OPTIONAL_FN(http2_var_lookup);
 }
 
 /* Install this module into the apache2 infrastructure.
@@ -125,7 +139,7 @@ static void h2_hooks(apr_pool_t *pool)
 {
     static const char *const mod_ssl[] = { "mod_ssl.c", NULL};
     
-    ap_log_perror(APLOG_MARK, APLOG_INFO, 0, pool, "installing hooks");
+    ap_log_perror(APLOG_MARK, APLOG_TRACE1, 0, pool, "installing hooks");
     
     /* Run once after configuration is set, but before mpm children initialize.
      */
@@ -141,6 +155,92 @@ static void h2_hooks(apr_pool_t *pool)
 
     h2_alt_svc_register_hooks();
     
+    /* Setup subprocess env for certain variables 
+     */
+    ap_hook_fixups(h2_h2_fixups, NULL,NULL, APR_HOOK_MIDDLE);
+    
+    /* test http2 connection status handler */
+    ap_hook_handler(h2_filter_h2_status_handler, NULL, NULL, APR_HOOK_MIDDLE);
+}
+
+static char *value_of_HTTP2(apr_pool_t *p, server_rec *s,
+                              conn_rec *c, request_rec *r)
+{
+    return c && http2_is_h2(c)? "on" : "off";
 }
 
+static char *value_of_H2PUSH(apr_pool_t *p, server_rec *s,
+                             conn_rec *c, request_rec *r)
+{
+    h2_ctx *ctx;
+    if (r) {
+        ctx = h2_ctx_rget(r);
+        if (ctx) {
+            h2_task *task = h2_ctx_get_task(ctx);
+            return (task && task->request->push_policy != H2_PUSH_NONE)? "on"
: "off";
+        }
+    }
+    else if (c) {
+        ctx = h2_ctx_get(c, 0);
+        return ctx && h2_session_push_enabled(ctx->session)? "on" : "off";
+    }
+    else if (s) {
+        const h2_config *cfg = h2_config_sget(s);
+        return cfg && h2_config_geti(cfg, H2_CONF_PUSH)? "on" : "off";
+    }
+    return "off";
+}
 
+typedef char *h2_var_lookup(apr_pool_t *p, server_rec *s,
+                             conn_rec *c, request_rec *r);
+typedef struct h2_var_def {
+    const char *name;
+    h2_var_lookup *lookup;
+    unsigned int  subprocess : 1;    /* should be set in r->subprocess_env */
+} h2_var_def;
+
+static h2_var_def H2_VARS[] = {
+    { "HTTP2",     value_of_HTTP2,  1 },
+    { "H2PUSH",    value_of_H2PUSH, 1 },
+};
+
+#ifndef H2_ALEN
+#define H2_ALEN(a)          (sizeof(a)/sizeof((a)[0]))
+#endif
+
+
+static int http2_is_h2(conn_rec *c)
+{
+    return h2_ctx_get(c->master? c->master : c, 0) != NULL;
+}
+
+static char *http2_var_lookup(apr_pool_t *p, server_rec *s,
+                              conn_rec *c, request_rec *r, char *name)
+{
+    int i;
+    /* If the # of vars grow, we need to put definitions in a hash */
+    for (i = 0; i < H2_ALEN(H2_VARS); ++i) {
+        h2_var_def *vdef = &H2_VARS[i];
+        if (!strcmp(vdef->name, name)) {
+            return vdef->lookup(p, s, c, r);
+        }
+    }
+    return "";
+}
+
+static int h2_h2_fixups(request_rec *r)
+{
+    if (r->connection->master) {
+        h2_ctx *ctx = h2_ctx_rget(r);
+        int i;
+        
+        for (i = 0; ctx && i < H2_ALEN(H2_VARS); ++i) {
+            h2_var_def *vdef = &H2_VARS[i];
+            if (vdef->subprocess) {
+                apr_table_setn(r->subprocess_env, vdef->name, 
+                               vdef->lookup(r->pool, r->server, r->connection,
r));
+            }
+        }
+    }
+    return DECLINED;
+}

Added: httpd/httpd/branches/2.4.x/modules/http2/mod_http2.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/http2/mod_http2.h?rev=1725301&view=auto
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/http2/mod_http2.h (added)
+++ httpd/httpd/branches/2.4.x/modules/http2/mod_http2.h Mon Jan 18 16:22:57 2016
@@ -0,0 +1,30 @@
+/* Copyright 2015 greenbytes GmbH (https://www.greenbytes.de)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef mod_http2_mod_http2_h
+#define mod_http2_mod_http2_h
+
+/** The http2_var_lookup() optional function retrieves HTTP2 environment
+ * variables. */
+APR_DECLARE_OPTIONAL_FN(char *, http2_var_lookup,
+                        (apr_pool_t *, server_rec *,
+                         conn_rec *, request_rec *,
+                         char *));
+
+/** An optional function which returns non-zero if the given connection
+ * or its master connection is using HTTP/2. */
+APR_DECLARE_OPTIONAL_FN(int, http2_is_h2, (conn_rec *));
+
+#endif



Mime
View raw message