فهرست منبع

Add mod_http2 stub

bel2125 5 سال پیش
والد
کامیت
9cc21590ca
4فایلهای تغییر یافته به همراه21 افزوده شده و 4 حذف شده
  1. 2 1
      VisualStudio/civetweb_lua/civetweb_lua.vcxproj
  2. 3 0
      VisualStudio/civetweb_lua/civetweb_lua.vcxproj.filters
  3. 11 3
      src/civetweb.c
  4. 5 0
      src/mod_http2.inl

+ 2 - 1
VisualStudio/civetweb_lua/civetweb_lua.vcxproj

@@ -102,7 +102,7 @@
       </PrecompiledHeader>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>MG_EXPERIMENTAL_INTERFACES;USE_SERVER_STATS;USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_LUA_LUAXML;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>USE_HTTP2;MG_EXPERIMENTAL_INTERFACES;USE_SERVER_STATS;USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_LUA_LUAXML;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>
@@ -207,6 +207,7 @@
   <ItemGroup>
     <None Include="..\..\src\handle_form.inl" />
     <None Include="..\..\src\md5.inl" />
+    <None Include="..\..\src\mod_http2.inl" />
     <None Include="..\..\src\mod_lua_shared.inl" />
     <None Include="..\..\src\sha1.inl" />
     <None Include="..\..\src\mod_duktape.inl" />

+ 3 - 0
VisualStudio/civetweb_lua/civetweb_lua.vcxproj.filters

@@ -71,5 +71,8 @@
     <None Include="..\..\src\mod_lua_shared.inl">
       <Filter>inl files</Filter>
     </None>
+    <None Include="..\..\src\mod_http2.inl">
+      <Filter>inl files</Filter>
+    </None>
   </ItemGroup>
 </Project>

+ 11 - 3
src/civetweb.c

@@ -14708,10 +14708,16 @@ handle_request(struct mg_connection *conn)
 #endif /* !defined(NO_FILES) */
 }
 
+
+/* Include HTTP/2 modules */
 #ifdef USE_HTTP2
+#if defined(NO_SSL)
+#error "HTTP2 requires ALPN, APLN requires SSL/TLS"
+#endif
 #include "mod_http2.inl"
 #endif
 
+
 #if !defined(NO_FILESYSTEMS)
 static void
 handle_file_based_request(struct mg_connection *conn,
@@ -18867,17 +18873,19 @@ worker_thread_run(struct mg_connection *conn)
 				ssl_get_client_cert_info(conn);
 
 				/* process HTTPS connection */
-				if (!memcmp(tls.alpn_proto, "\x02h2", 3)) {
+#if defined(USE_HTTP2)
+				if ((tls.alpn_proto != NULL)
+				    && (!memcmp(tls.alpn_proto, "\x02h2", 3))) {
 					/* process HTTPS/2 connection */
 					init_connection(conn);
 					conn->connection_type = CONNECTION_TYPE_REQUEST;
 					conn->protocol_type = PROTOCOL_TYPE_HTTP2;
 					conn->content_len = -1;
 					conn->is_chunked = 0;
-#ifdef USE_HTTP2
 					process_new_http2_connection(conn);
+				} else
 #endif
-				} else {
+				{
 					/* process HTTPS/1.x or WEBSOCKET-SECURE connection */
 					process_new_connection(conn);
 				}

+ 5 - 0
src/mod_http2.inl

@@ -0,0 +1,5 @@
+/* Stub for HTTP/2 */
+static void process_new_http2_connection(struct mg_connection *conn)
+{
+	mg_send_http_error(conn, 505, "%s", "HTTP/2 not supported");
+}