Merge "Merge: migrate appfw from meta-agl-extra"
[AGL/meta-agl.git] / meta-app-framework / recipes-support / libmicrohttpd / libmicrohttpd / allows-upgrade.patch
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
4 @@ -708,6 +708,8 @@
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
9 + * to keep-alive.
10   *
11   * @param connection the connection to check for keepalive
12   * @return #MHD_YES if (based on the request), a keepalive is
13 @@ -750,6 +752,59 @@
14  
15  
16  /**
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.
29 + *
30 + * @param connection the connection to check for keepalive
31 + * @return #MHD_YES if (based on the request), a keepalive is
32 + *        legal
33 + */
34 +static int
35 +should_keepalive (struct MHD_Connection *connection)
36 +{
37 +  const char *end;
38 +
39 +  if (NULL == connection->version)
40 +    return MHD_NO;
41 +  if ( (NULL != connection->response) &&
42 +       (0 != (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) )
43 +    return MHD_NO;
44 +  end = MHD_lookup_connection_value (connection,
45 +                                     MHD_HEADER_KIND,
46 +                                     MHD_HTTP_HEADER_CONNECTION);
47 +  if (MHD_str_equal_caseless_(connection->version,
48 +                       MHD_HTTP_VERSION_1_1))
49 +  {
50 +    if (NULL == end)
51 +      return MHD_YES;
52 +    if ( (MHD_str_equal_caseless_ (end, "close")) )
53 +      return MHD_NO;
54 +   return MHD_YES;
55 +  }
56 +  if (MHD_str_equal_caseless_(connection->version,
57 +                       MHD_HTTP_VERSION_1_0))
58 +  {
59 +    if (NULL == end)
60 +      return MHD_NO;
61 +    if (MHD_str_equal_caseless_(end, "Keep-Alive"))
62 +      return MHD_YES;
63 +    return MHD_NO;
64 +  }
65 +  return MHD_NO;
66 +}
67 +
68 +
69 +/**
70   * Produce HTTP "Date:" header.
71   *
72   * @param date where to write the header, with
73 @@ -2795,7 +2850,7 @@
74              }
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)))
79              {
80                /* have to close for some reason */
81                MHD_connection_close_ (connection,