Jelajahi Sumber

RFC compliance: use chunked even for non-Keep-Alive HTTP/1.1 clients

Evgeny Grin (Karlson2k) 4 tahun lalu
induk
melakukan
496900010b
2 mengubah file dengan 9 tambahan dan 6 penghapusan
  1. 1 1
      src/include/microhttpd.h
  2. 8 5
      src/microhttpd/connection.c

+ 1 - 1
src/include/microhttpd.h

@@ -131,7 +131,7 @@ typedef intptr_t ssize_t;
  * they are parsed as decimal numbers.
  * Example: 0x01093001 = 1.9.30-1.
  */
-#define MHD_VERSION 0x00097305
+#define MHD_VERSION 0x00097306
 
 
 #ifdef __has_attribute

+ 8 - 5
src/microhttpd/connection.c

@@ -1630,19 +1630,22 @@ setup_reply_properties (struct MHD_Connection *connection)
       else if (0 != (r->flags & (MHD_RF_HTTP_VERSION_1_0_ONLY
                                  | MHD_RF_HTTP_VERSION_1_0_RESPONSE)))
         use_chunked = false;
-      /* TODO: Use chunked for HTTP/1.1 non-Keep-Alive */
-      else if (0 != (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED))
-        use_chunked = true;
-      else if (! use_keepalive)
-        use_chunked = false;
       else
+        /* If chunked encoding is supported and allowed, and response size
+         * is unknown, use chunked even for non-Keep-Alive connections.
+         * See https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.3
+         * Also use chunked if it is enforced by application and supported by
+         * the client. */
         use_chunked = true;
     }
     else
       use_chunked = false;
 
     if ( (MHD_SIZE_UNKNOWN == r->total_size) && ! use_chunked)
+    {
+      mhd_assert (! MHD_IS_HTTP_VER_1_1_COMPAT (c->http_ver));
       use_keepalive = false; /* End of the stream is indicated by closure */
+    }
   }
 
   c->rp_props.chunked = use_chunked;