[nginx] The HTTP/2 implementation (RFC 7240, 7241).

Valentin Bartenev vbart at nginx.com
Thu Sep 17 13:54:25 UTC 2015


details:   http://hg.nginx.org/nginx/rev/257b51c37c5a
branches:  
changeset: 6246:257b51c37c5a
user:      Valentin Bartenev <vbart at nginx.com>
date:      Fri Sep 11 20:13:06 2015 +0300
description:
The HTTP/2 implementation (RFC 7240, 7241).

The SPDY support is removed, as it's incompatible with the new module.

diffstat:

 auto/make                               |     2 +-
 auto/modules                            |    18 +-
 auto/options                            |     6 +-
 auto/sources                            |    18 +-
 src/core/ngx_connection.h               |     2 +-
 src/http/modules/ngx_http_ssl_module.c  |    24 +-
 src/http/ngx_http.c                     |    31 +-
 src/http/ngx_http.h                     |     8 +-
 src/http/ngx_http_core_module.c         |    29 +-
 src/http/ngx_http_core_module.h         |     8 +-
 src/http/ngx_http_request.c             |    41 +-
 src/http/ngx_http_request.h             |     5 +-
 src/http/ngx_http_request_body.c        |    12 +-
 src/http/ngx_http_spdy.c                |  3701 ----------------------------
 src/http/ngx_http_spdy.h                |   261 --
 src/http/ngx_http_spdy_filter_module.c  |  1222 ---------
 src/http/ngx_http_spdy_module.c         |   408 ---
 src/http/ngx_http_spdy_module.h         |    41 -
 src/http/ngx_http_upstream.c            |     8 +-
 src/http/v2/ngx_http_v2.c               |  3964 +++++++++++++++++++++++++++++++
 src/http/v2/ngx_http_v2.h               |   334 ++
 src/http/v2/ngx_http_v2_filter_module.c |  1290 ++++++++++
 src/http/v2/ngx_http_v2_huff_decode.c   |  2714 +++++++++++++++++++++
 src/http/v2/ngx_http_v2_huff_encode.c   |    10 +
 src/http/v2/ngx_http_v2_module.c        |   469 +++
 src/http/v2/ngx_http_v2_module.h        |    42 +
 src/http/v2/ngx_http_v2_table.c         |   349 ++
 27 files changed, 9283 insertions(+), 5734 deletions(-)

diffs (truncated from 15414 to 300 lines):

diff -r 3cf25d33886a -r 257b51c37c5a auto/make
--- a/auto/make	Fri Sep 11 17:04:40 2015 +0300
+++ b/auto/make	Fri Sep 11 20:13:06 2015 +0300
@@ -7,7 +7,7 @@ echo "creating $NGX_MAKEFILE"
 
 mkdir -p $NGX_OBJS/src/core $NGX_OBJS/src/event $NGX_OBJS/src/event/modules \
          $NGX_OBJS/src/os/unix $NGX_OBJS/src/os/win32 \
-         $NGX_OBJS/src/http $NGX_OBJS/src/http/modules \
+         $NGX_OBJS/src/http $NGX_OBJS/src/http/v2 $NGX_OBJS/src/http/modules \
          $NGX_OBJS/src/http/modules/perl \
          $NGX_OBJS/src/mail \
          $NGX_OBJS/src/stream \
diff -r 3cf25d33886a -r 257b51c37c5a auto/modules
--- a/auto/modules	Fri Sep 11 17:04:40 2015 +0300
+++ b/auto/modules	Fri Sep 11 20:13:06 2015 +0300
@@ -94,7 +94,7 @@ fi
 #     ngx_http_write_filter
 #     ngx_http_header_filter
 #     ngx_http_chunked_filter
-#     ngx_http_spdy_filter
+#     ngx_http_v2_filter
 #     ngx_http_range_header_filter
 #     ngx_http_gzip_filter
 #     ngx_http_postpone_filter
@@ -115,8 +115,8 @@ HTTP_FILTER_MODULES="$HTTP_WRITE_FILTER_
                      $HTTP_HEADER_FILTER_MODULE \
                      $HTTP_CHUNKED_FILTER_MODULE"
 
-if [ $HTTP_SPDY = YES ]; then
-    HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_SPDY_FILTER_MODULE"
+if [ $HTTP_V2 = YES ]; then
+    HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_V2_FILTER_MODULE"
 fi
 
 HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_RANGE_HEADER_FILTER_MODULE"
@@ -180,12 +180,12 @@ if [ $HTTP_USERID = YES ]; then
 fi
 
 
-if [ $HTTP_SPDY = YES ]; then
-    have=NGX_HTTP_SPDY . auto/have
-    USE_ZLIB=YES
-    HTTP_MODULES="$HTTP_MODULES $HTTP_SPDY_MODULE"
-    HTTP_DEPS="$HTTP_DEPS $HTTP_SPDY_DEPS"
-    HTTP_SRCS="$HTTP_SRCS $HTTP_SPDY_SRCS"
+if [ $HTTP_V2 = YES ]; then
+    have=NGX_HTTP_V2 . auto/have
+    HTTP_MODULES="$HTTP_MODULES $HTTP_V2_MODULE"
+    HTTP_INCS="$HTTP_INCS $HTTP_V2_INCS"
+    HTTP_DEPS="$HTTP_DEPS $HTTP_V2_DEPS"
+    HTTP_SRCS="$HTTP_SRCS $HTTP_V2_SRCS"
 fi
 
 HTTP_MODULES="$HTTP_MODULES $HTTP_STATIC_MODULE"
diff -r 3cf25d33886a -r 257b51c37c5a auto/options
--- a/auto/options	Fri Sep 11 17:04:40 2015 +0300
+++ b/auto/options	Fri Sep 11 20:13:06 2015 +0300
@@ -58,7 +58,7 @@ HTTP_CACHE=YES
 HTTP_CHARSET=YES
 HTTP_GZIP=YES
 HTTP_SSL=NO
-HTTP_SPDY=NO
+HTTP_V2=NO
 HTTP_SSI=YES
 HTTP_POSTPONE=NO
 HTTP_REALIP=NO
@@ -210,7 +210,7 @@ do
         --http-scgi-temp-path=*)         NGX_HTTP_SCGI_TEMP_PATH="$value" ;;
 
         --with-http_ssl_module)          HTTP_SSL=YES               ;;
-        --with-http_spdy_module)         HTTP_SPDY=YES              ;;
+        --with-http_v2_module)           HTTP_V2=YES                ;;
         --with-http_realip_module)       HTTP_REALIP=YES            ;;
         --with-http_addition_module)     HTTP_ADDITION=YES          ;;
         --with-http_xslt_module)         HTTP_XSLT=YES              ;;
@@ -378,7 +378,7 @@ cat << END
   --with-ipv6                        enable IPv6 support
 
   --with-http_ssl_module             enable ngx_http_ssl_module
-  --with-http_spdy_module            enable ngx_http_spdy_module
+  --with-http_v2_module              enable ngx_http_v2_module
   --with-http_realip_module          enable ngx_http_realip_module
   --with-http_addition_module        enable ngx_http_addition_module
   --with-http_xslt_module            enable ngx_http_xslt_module
diff -r 3cf25d33886a -r 257b51c37c5a auto/sources
--- a/auto/sources	Fri Sep 11 17:04:40 2015 +0300
+++ b/auto/sources	Fri Sep 11 20:13:06 2015 +0300
@@ -317,13 +317,17 @@ HTTP_POSTPONE_FILTER_SRCS=src/http/ngx_h
 HTTP_FILE_CACHE_SRCS=src/http/ngx_http_file_cache.c
 
 
-HTTP_SPDY_MODULE=ngx_http_spdy_module
-HTTP_SPDY_FILTER_MODULE=ngx_http_spdy_filter_module
-HTTP_SPDY_DEPS="src/http/ngx_http_spdy.h \
-                src/http/ngx_http_spdy_module.h"
-HTTP_SPDY_SRCS="src/http/ngx_http_spdy.c \
-                src/http/ngx_http_spdy_module.c \
-                src/http/ngx_http_spdy_filter_module.c"
+HTTP_V2_MODULE=ngx_http_v2_module
+HTTP_V2_FILTER_MODULE=ngx_http_v2_filter_module
+HTTP_V2_INCS="src/http/v2"
+HTTP_V2_DEPS="src/http/v2/ngx_http_v2.h \
+              src/http/v2/ngx_http_v2_module.h"
+HTTP_V2_SRCS="src/http/v2/ngx_http_v2.c \
+              src/http/v2/ngx_http_v2_table.c \
+              src/http/v2/ngx_http_v2_huff_decode.c \
+              src/http/v2/ngx_http_v2_huff_encode.c \
+              src/http/v2/ngx_http_v2_module.c \
+              src/http/v2/ngx_http_v2_filter_module.c"
 
 
 HTTP_CHARSET_FILTER_MODULE=ngx_http_charset_filter_module
diff -r 3cf25d33886a -r 257b51c37c5a src/core/ngx_connection.h
--- a/src/core/ngx_connection.h	Fri Sep 11 17:04:40 2015 +0300
+++ b/src/core/ngx_connection.h	Fri Sep 11 20:13:06 2015 +0300
@@ -118,7 +118,7 @@ typedef enum {
 
 #define NGX_LOWLEVEL_BUFFERED  0x0f
 #define NGX_SSL_BUFFERED       0x01
-#define NGX_SPDY_BUFFERED      0x02
+#define NGX_HTTP_V2_BUFFERED   0x02
 
 
 struct ngx_connection_s {
diff -r 3cf25d33886a -r 257b51c37c5a src/http/modules/ngx_http_ssl_module.c
--- a/src/http/modules/ngx_http_ssl_module.c	Fri Sep 11 17:04:40 2015 +0300
+++ b/src/http/modules/ngx_http_ssl_module.c	Fri Sep 11 20:13:06 2015 +0300
@@ -326,10 +326,10 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t 
 #if (NGX_DEBUG)
     unsigned int            i;
 #endif
-#if (NGX_HTTP_SPDY)
+#if (NGX_HTTP_V2)
     ngx_http_connection_t  *hc;
 #endif
-#if (NGX_HTTP_SPDY || NGX_DEBUG)
+#if (NGX_HTTP_V2 || NGX_DEBUG)
     ngx_connection_t       *c;
 
     c = ngx_ssl_get_connection(ssl_conn);
@@ -342,12 +342,13 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t 
     }
 #endif
 
-#if (NGX_HTTP_SPDY)
+#if (NGX_HTTP_V2)
     hc = c->data;
 
-    if (hc->addr_conf->spdy) {
-        srv = (unsigned char *) NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
-        srvlen = sizeof(NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
+    if (hc->addr_conf->http2) {
+        srv =
+           (unsigned char *) NGX_HTTP_V2_ALPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
+        srvlen = sizeof(NGX_HTTP_V2_ALPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
 
     } else
 #endif
@@ -378,22 +379,23 @@ static int
 ngx_http_ssl_npn_advertised(ngx_ssl_conn_t *ssl_conn,
     const unsigned char **out, unsigned int *outlen, void *arg)
 {
-#if (NGX_HTTP_SPDY || NGX_DEBUG)
+#if (NGX_HTTP_V2 || NGX_DEBUG)
     ngx_connection_t  *c;
 
     c = ngx_ssl_get_connection(ssl_conn);
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "SSL NPN advertised");
 #endif
 
-#if (NGX_HTTP_SPDY)
+#if (NGX_HTTP_V2)
     {
     ngx_http_connection_t  *hc;
 
     hc = c->data;
 
-    if (hc->addr_conf->spdy) {
-        *out = (unsigned char *) NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
-        *outlen = sizeof(NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
+    if (hc->addr_conf->http2) {
+        *out =
+            (unsigned char *) NGX_HTTP_V2_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
+        *outlen = sizeof(NGX_HTTP_V2_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
 
         return SSL_TLSEXT_ERR_OK;
     }
diff -r 3cf25d33886a -r 257b51c37c5a src/http/ngx_http.c
--- a/src/http/ngx_http.c	Fri Sep 11 17:04:40 2015 +0300
+++ b/src/http/ngx_http.c	Fri Sep 11 20:13:06 2015 +0300
@@ -1233,8 +1233,8 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
 #if (NGX_HTTP_SSL)
     ngx_uint_t             ssl;
 #endif
-#if (NGX_HTTP_SPDY)
-    ngx_uint_t             spdy;
+#if (NGX_HTTP_V2)
+    ngx_uint_t             http2;
 #endif
 
     /*
@@ -1290,8 +1290,8 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
 #if (NGX_HTTP_SSL)
         ssl = lsopt->ssl || addr[i].opt.ssl;
 #endif
-#if (NGX_HTTP_SPDY)
-        spdy = lsopt->spdy || addr[i].opt.spdy;
+#if (NGX_HTTP_V2)
+        http2 = lsopt->http2 || addr[i].opt.http2;
 #endif
 
         if (lsopt->set) {
@@ -1324,8 +1324,8 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
 #if (NGX_HTTP_SSL)
         addr[i].opt.ssl = ssl;
 #endif
-#if (NGX_HTTP_SPDY)
-        addr[i].opt.spdy = spdy;
+#if (NGX_HTTP_V2)
+        addr[i].opt.http2 = http2;
 #endif
 
         return NGX_OK;
@@ -1357,14 +1357,17 @@ ngx_http_add_address(ngx_conf_t *cf, ngx
         }
     }
 
-#if (NGX_HTTP_SPDY && NGX_HTTP_SSL                                            \
+#if (NGX_HTTP_V2 && NGX_HTTP_SSL                                              \
      && !defined TLSEXT_TYPE_application_layer_protocol_negotiation           \
      && !defined TLSEXT_TYPE_next_proto_neg)
-    if (lsopt->spdy && lsopt->ssl) {
+
+    if (lsopt->http2 && lsopt->ssl) {
         ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
-                           "nginx was built without OpenSSL ALPN or NPN "
-                           "support, SPDY is not enabled for %s", lsopt->addr);
+                           "nginx was built with OpenSSL that lacks ALPN "
+                           "and NPN support, HTTP/2 is not enabled for %s",
+                           lsopt->addr);
     }
+
 #endif
 
     addr = ngx_array_push(&port->addrs);
@@ -1856,8 +1859,8 @@ ngx_http_add_addrs(ngx_conf_t *cf, ngx_h
 #if (NGX_HTTP_SSL)
         addrs[i].conf.ssl = addr[i].opt.ssl;
 #endif
-#if (NGX_HTTP_SPDY)
-        addrs[i].conf.spdy = addr[i].opt.spdy;
+#if (NGX_HTTP_V2)
+        addrs[i].conf.http2 = addr[i].opt.http2;
 #endif
         addrs[i].conf.proxy_protocol = addr[i].opt.proxy_protocol;
 
@@ -1921,8 +1924,8 @@ ngx_http_add_addrs6(ngx_conf_t *cf, ngx_
 #if (NGX_HTTP_SSL)
         addrs6[i].conf.ssl = addr[i].opt.ssl;
 #endif
-#if (NGX_HTTP_SPDY)
-        addrs6[i].conf.spdy = addr[i].opt.spdy;
+#if (NGX_HTTP_V2)
+        addrs6[i].conf.http2 = addr[i].opt.http2;
 #endif
 
         if (addr[i].hash.buckets == NULL
diff -r 3cf25d33886a -r 257b51c37c5a src/http/ngx_http.h
--- a/src/http/ngx_http.h	Fri Sep 11 17:04:40 2015 +0300
+++ b/src/http/ngx_http.h	Fri Sep 11 20:13:06 2015 +0300
@@ -20,8 +20,8 @@ typedef struct ngx_http_file_cache_s  ng
 typedef struct ngx_http_log_ctx_s     ngx_http_log_ctx_t;
 typedef struct ngx_http_chunked_s     ngx_http_chunked_t;
 
-#if (NGX_HTTP_SPDY)
-typedef struct ngx_http_spdy_stream_s  ngx_http_spdy_stream_t;
+#if (NGX_HTTP_V2)
+typedef struct ngx_http_v2_stream_s   ngx_http_v2_stream_t;
 #endif
 
 typedef ngx_int_t (*ngx_http_header_handler_pt)(ngx_http_request_t *r,
@@ -38,8 +38,8 @@ typedef u_char *(*ngx_http_log_handler_p
 #include <ngx_http_upstream_round_robin.h>
 #include <ngx_http_core_module.h>
 
-#if (NGX_HTTP_SPDY)
-#include <ngx_http_spdy.h>
+#if (NGX_HTTP_V2)
+#include <ngx_http_v2.h>
 #endif
 #if (NGX_HTTP_CACHE)
 #include <ngx_http_cache.h>
diff -r 3cf25d33886a -r 257b51c37c5a src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c	Fri Sep 11 17:04:40 2015 +0300
+++ b/src/http/ngx_http_core_module.c	Fri Sep 11 20:13:06 2015 +0300
@@ -2132,13 +2132,6 @@ ngx_http_gzip_ok(ngx_http_request_t *r)
         return NGX_DECLINED;
     }
 
-#if (NGX_HTTP_SPDY)



More information about the nginx-devel mailing list