Explorar el Código

Add option to enable/disable HTTP2

bel2125 hace 5 años
padre
commit
6bb354ce0f
Se han modificado 3 ficheros con 25 adiciones y 16 borrados
  1. 2 2
      VisualStudio/civetweb_lua/civetweb_lua.vcxproj
  2. 22 13
      src/civetweb.c
  3. 1 1
      src/mod_http2.inl

+ 2 - 2
VisualStudio/civetweb_lua/civetweb_lua.vcxproj

@@ -119,7 +119,7 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>USE_SERVER_STATS;USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>USE_HTTP2;USE_SERVER_STATS;USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
@@ -170,7 +170,7 @@
       <Optimization>MaxSpeed</Optimization>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <PreprocessorDefinitions>USE_SERVER_STATS;USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>USE_HTTP2;USE_SERVER_STATS;USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>

+ 22 - 13
src/civetweb.c

@@ -2547,6 +2547,9 @@ enum {
 #if defined(USE_TIMERS)
 	CGI_TIMEOUT,
 #endif
+#if defined(USE_HTTP2)
+	ENABLE_HTTP2,
+#endif
 
 	/* Once for each domain */
 	DOCUMENT_ROOT,
@@ -2655,6 +2658,9 @@ static const struct mg_option config_options[] = {
 #if defined(USE_TIMERS)
     {"cgi_timeout_ms", MG_CONFIG_TYPE_NUMBER, NULL},
 #endif
+#if defined(USE_HTTP2)
+    {"enable_http2", MG_CONFIG_TYPE_BOOLEAN, "no"},
+#endif
 
     /* Once for each domain */
     {"document_root", MG_CONFIG_TYPE_DIRECTORY, NULL},
@@ -16401,20 +16407,17 @@ ssl_servername_callback(SSL *ssl, int *ad, void *arg)
 }
 
 
-#if defined(USE_HTTP2)
 static const char alpn_proto_list[] = "\x02h2\x08http/1.1\x08http/1.0";
-static const char *alpn_proto_order[] = {alpn_proto_list,
-                                         alpn_proto_list + 3,
-                                         alpn_proto_list + 3 + 8,
-                                         NULL};
-#else
-static const char alpn_proto_list[] = "\x08http/1.1\x08http/1.0";
-static const char *alpn_proto_order[] = {alpn_proto_list,
-                                         alpn_proto_list + 8,
-                                         NULL};
+static const char *alpn_proto_order_http1[] = {alpn_proto_list + 3,
+                                               alpn_proto_list + 3 + 8,
+                                               NULL};
+#if defined(USE_HTTP2)
+static const char *alpn_proto_order_http2[] = {alpn_proto_list,
+                                               alpn_proto_list + 3,
+                                               alpn_proto_list + 3 + 8,
+                                               NULL};
 #endif
 
-
 static int
 alpn_select_cb(SSL *ssl,
                const unsigned char **out,
@@ -16424,14 +16427,20 @@ alpn_select_cb(SSL *ssl,
                void *arg)
 {
 	struct mg_domain_context *dom_ctx = (struct mg_domain_context *)arg;
-	unsigned int i, j;
+	unsigned int i, j, enable_http2 = 0;
+	const char **alpn_proto_order = alpn_proto_order_http1;
 
 	struct mg_workerTLS *tls =
 	    (struct mg_workerTLS *)pthread_getspecific(sTlsKey);
 
 	(void)ssl;
-	(void)dom_ctx;
 
+#if defined(USE_HTTP2)
+	enable_http2 = (0 != strcmp(dom_ctx->config[ENABLE_HTTP2], "yes"));
+	if (enable_http2) {
+		alpn_proto_order = alpn_proto_order_http2;
+	}
+#endif
 
 	if (tls == NULL) {
 		/* Need to store protocol in Thread Local Storage */

+ 1 - 1
src/mod_http2.inl

@@ -628,7 +628,7 @@ hpack_getnum(const uint8_t *buf,
              uint8_t idx_mask,
              struct mg_context *ctx)
 {
-	uint64_t num = buf[*i] & idx_mask;
+	uint64_t num = (buf[*i] & idx_mask);
 
 	(void)ctx;