summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-11-02 11:00:53 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-11-02 12:21:06 +0300
commitcbd93766919531e3986e5a9c838df61e696a07f0 (patch)
tree8d208299202b74d37dc8494a287c2d2c2d789315
parent384cb2ab655970311ef89993810f7b62ad55b189 (diff)
'Upgrade' connections: simplify daemon options
-rw-r--r--src/include/microhttpd.h13
-rw-r--r--src/microhttpd/connection.c22
-rw-r--r--src/microhttpd/daemon.c7
-rw-r--r--src/microhttpd/response.c3
-rw-r--r--src/microhttpd/test_upgrade.c2
-rw-r--r--src/microhttpd/test_upgrade_ssl.c8
6 files changed, 24 insertions, 31 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index a099d47f..2a46c3e0 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -126,7 +126,7 @@ typedef intptr_t ssize_t;
* Current version of the library.
* 0x01093001 = 1.9.30-1.
*/
-#define MHD_VERSION 0x00095204
+#define MHD_VERSION 0x00095205
/**
* MHD-internal return code for "YES".
@@ -686,14 +686,11 @@ enum MHD_FLAG
MHD_USE_TCP_FASTOPEN = 16384,
/**
- * You need to set this option if you want to use epoll() in
- * combination with HTTPS connections and switching protocols via
- * connection upgrades (via #MHD_create_response_for_upgrade()).
- * This flag is required as under these circumstances we need to
- * open up an extra file descriptor, which we do not want to do
- * unless necessary.
+ * You need to set this option if you want to use HTTP "Upgrade".
+ * "Upgrade" may require usage of additional internal resources,
+ * which we do not want to use unless necessary.
*/
- MHD_USE_TLS_EPOLL_UPGRADE = 32768 | MHD_USE_SUSPEND_RESUME | MHD_USE_EPOLL | MHD_USE_TLS
+ MHD_ALLOW_UPGRADE = 32768
};
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 6b0501e8..95b60f14 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3437,33 +3437,21 @@ MHD_queue_response (struct MHD_Connection *connection,
(MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) )
return MHD_NO;
daemon = connection->daemon;
- if ( (MHD_HTTP_SWITCHING_PROTOCOLS != status_code) &&
- (NULL != response->upgrade_handler) )
- {
-#ifdef HAVE_MESSAGES
- MHD_DLOG (daemon,
- _("Application used invalid status code for 'upgrade' response!\n"));
-#endif
- return MHD_NO;
- }
if ( (NULL != response->upgrade_handler) &&
- (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
- (0 == (daemon->options & MHD_USE_SUSPEND_RESUME)) )
+ (0 == (daemon->options & MHD_ALLOW_UPGRADE)) )
{
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- _("Application attempted 'upgrade' without setting MHD_USE_SUSPEND_RESUME!\n"));
+ _("Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n"));
#endif
return MHD_NO;
}
- if ( (NULL != response->upgrade_handler) &&
- (0 != (MHD_USE_EPOLL & daemon->options)) &&
- (0 != (MHD_USE_TLS & daemon->options)) &&
- (MHD_USE_TLS_EPOLL_UPGRADE != (MHD_USE_TLS_EPOLL_UPGRADE & daemon->options)) )
+ if ( (MHD_HTTP_SWITCHING_PROTOCOLS != status_code) &&
+ (NULL != response->upgrade_handler) )
{
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- _("Application attempted 'upgrade' HTTPS connection in epoll mode without setting MHD_USE_HTTPS_EPOLL_UPGRADE!\n"));
+ _("Application used invalid status code for 'upgrade' response!\n"));
#endif
return MHD_NO;
}
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index b192dbfb..c388e6ad 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -4604,7 +4604,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
if (-1 == daemon->epoll_fd)
return MHD_NO;
#if HTTPS_SUPPORT
- if (MHD_USE_TLS_EPOLL_UPGRADE == (MHD_USE_TLS_EPOLL_UPGRADE & daemon->options))
+ if (0 != (MHD_ALLOW_UPGRADE & daemon->options))
{
daemon->epoll_upgrade_fd = setup_epoll_fd (daemon);
if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd)
@@ -4751,6 +4751,11 @@ MHD_start_daemon_va (unsigned int flags,
daemon->custom_error_log = (MHD_LogCallback) &vfprintf;
daemon->custom_error_log_cls = stderr;
#endif
+ if (0 != (daemon->options & MHD_ALLOW_UPGRADE))
+ {
+ daemon->options |= MHD_USE_SUSPEND_RESUME;
+ flags |= MHD_USE_SUSPEND_RESUME;
+ }
#ifdef HAVE_LISTEN_SHUTDOWN
use_itc = (0 != (daemon->options & (MHD_USE_NO_LISTEN_SOCKET | MHD_USE_ITC)));
#else
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index db77dc6d..364acc15 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -691,6 +691,9 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
struct MHD_UpgradeResponseHandle *urh;
size_t rbo;
+ if (0 == (daemon->options & MHD_ALLOW_UPGRADE))
+ return MHD_NO;
+
if (NULL ==
MHD_get_response_header (response,
MHD_HTTP_HEADER_UPGRADE))
diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c
index 4cf52e4b..fff2d985 100644
--- a/src/microhttpd/test_upgrade.c
+++ b/src/microhttpd/test_upgrade.c
@@ -61,7 +61,7 @@ test_upgrade (int flags,
done = 0;
- d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_USE_SUSPEND_RESUME,
+ d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_ALLOW_UPGRADE,
1080,
NULL, NULL,
&ahc_upgrade, NULL,
diff --git a/src/microhttpd/test_upgrade_ssl.c b/src/microhttpd/test_upgrade_ssl.c
index a72fad6d..3aa55d1a 100644
--- a/src/microhttpd/test_upgrade_ssl.c
+++ b/src/microhttpd/test_upgrade_ssl.c
@@ -139,7 +139,7 @@ test_upgrade (int flags,
done = 0;
- d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_USE_SUSPEND_RESUME |MHD_USE_TLS,
+ d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_ALLOW_UPGRADE | MHD_USE_TLS,
1080,
NULL, NULL,
&ahc_upgrade, NULL,
@@ -198,7 +198,7 @@ main (int argc,
error_count += test_upgrade (0,
0);
#ifdef EPOLL_SUPPORT
- error_count += test_upgrade (MHD_USE_TLS_EPOLL_UPGRADE,
+ error_count += test_upgrade (MHD_USE_EPOLL | MHD_USE_TLS,
0);
#endif
@@ -221,10 +221,10 @@ main (int argc,
#endif
#ifdef EPOLL_SUPPORT
error_count += test_upgrade (MHD_USE_EPOLL_INTERNALLY |
- MHD_USE_TLS_EPOLL_UPGRADE,
+ MHD_USE_TLS,
0);
error_count += test_upgrade (MHD_USE_EPOLL_INTERNALLY |
- MHD_USE_TLS_EPOLL_UPGRADE,
+ MHD_USE_TLS,
2);
#endif
/* report result */