From 406da99114e5fb972793897ab1dc0e973e3b8057 Mon Sep 17 00:00:00 2001
From: Sam Hurst <samuelh@rd.bbc.co.uk>
Date: Wed, 25 Jul 2018 12:05:49 +0100
Subject: [PATCH] Don't set transfer encoding if content-length supplied

---
 src/microhttpd/connection.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 1778c59..555d18a 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -1419,6 +1419,7 @@ build_header_response (struct MHD_Connection *connection)
   bool client_requested_close;
   bool response_has_close;
   bool response_has_keepalive;
+  bool response_has_content_length;
   const char *have_encoding;
   const char *have_content_length;
   int must_add_close;
@@ -1483,6 +1484,7 @@ build_header_response (struct MHD_Connection *connection)
   must_add_keep_alive = MHD_NO;
   must_add_content_length = MHD_NO;
   response_has_close = false;
+  response_has_content_length = false;
   switch (connection->state)
     {
     case MHD_CONNECTION_FOOTERS_RECEIVED:
@@ -1495,6 +1497,8 @@ build_header_response (struct MHD_Connection *connection)
       client_requested_close = MHD_lookup_header_s_token_ci (connection,
                                                             MHD_HTTP_HEADER_CONNECTION,
                                                             "close");
+      if (NULL != MHD_get_response_header(connection->response, "Content-Length"))
+          response_has_content_length = true;
 
       if (0 != (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY))
         connection->keepalive = MHD_CONN_MUST_CLOSE;
@@ -1512,7 +1516,8 @@ build_header_response (struct MHD_Connection *connection)
            (NULL == connection->response->upgrade_handler) &&
 #endif /* UPGRADE_SUPPORT */
            (! response_has_close) &&
-           (! client_requested_close) )
+           (! client_requested_close) &&
+           (! response_has_content_length))
         {
           /* size is unknown, and close was not explicitly requested;
              need to either to HTTP 1.1 chunked encoding or
-- 
2.7.4

