1 diff -Naur a/src/microhttpd/connection.c b/src/microhttpd/connection.c
2 --- a/src/microhttpd/connection.c 2016-04-08 21:02:26.000000000 +0200
3 +++ b/src/microhttpd/connection.c 2016-08-29 22:41:53.790560238 +0200
5 * "keep-alive", we proceed to use the default for the respective HTTP
6 * version (which is conservative for HTTP 1.0, but might be a bit
7 * optimistic for HTTP 1.1).
8 + * In the case of Upgrade, the header Connection should not be set
11 * @param connection the connection to check for keepalive
12 * @return #MHD_YES if (based on the request), a keepalive is
17 + * Should we try to keep the given connection alive? We can use the
18 + * TCP stream for a second request if the connection is HTTP 1.1 and
19 + * the "Connection" header either does not exist or is not set to
20 + * "close", or if the connection is HTTP 1.0 and the "Connection"
21 + * header is explicitly set to "keep-alive". If no HTTP version is
22 + * specified (or if it is not 1.0 or 1.1), we definitively close the
23 + * connection. If the "Connection" header is not exactly "close" or
24 + * "keep-alive", we proceed to use the default for the respective HTTP
25 + * version (which is conservative for HTTP 1.0, but might be a bit
26 + * optimistic for HTTP 1.1).
27 + * In the case of Upgrade, the connection should be kept alive even if
28 + * the header Connection is not keep-alive.
30 + * @param connection the connection to check for keepalive
31 + * @return #MHD_YES if (based on the request), a keepalive is
35 +should_keepalive (struct MHD_Connection *connection)
39 + if (NULL == connection->version)
41 + if ( (NULL != connection->response) &&
42 + (0 != (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) )
44 + end = MHD_lookup_connection_value (connection,
46 + MHD_HTTP_HEADER_CONNECTION);
47 + if (MHD_str_equal_caseless_(connection->version,
48 + MHD_HTTP_VERSION_1_1))
52 + if ( (MHD_str_equal_caseless_ (end, "close")) )
56 + if (MHD_str_equal_caseless_(connection->version,
57 + MHD_HTTP_VERSION_1_0))
61 + if (MHD_str_equal_caseless_(end, "Keep-Alive"))
70 * Produce HTTP "Date:" header.
72 * @param date where to write the header, with
75 if (((MHD_YES == connection->read_closed) &&
76 (0 == connection->read_buffer_offset)) ||
77 - (MHD_NO == keepalive_possible (connection)))
78 + (MHD_NO == should_keepalive (connection)))
80 /* have to close for some reason */
81 MHD_connection_close_ (connection,