diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-11-02 11:00:53 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-11-02 12:21:06 +0300 |
commit | cbd93766919531e3986e5a9c838df61e696a07f0 (patch) | |
tree | 8d208299202b74d37dc8494a287c2d2c2d789315 | |
parent | 384cb2ab655970311ef89993810f7b62ad55b189 (diff) | |
download | libmicrohttpd-cbd93766919531e3986e5a9c838df61e696a07f0.tar.gz libmicrohttpd-cbd93766919531e3986e5a9c838df61e696a07f0.zip |
'Upgrade' connections: simplify daemon options
-rw-r--r-- | src/include/microhttpd.h | 13 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 22 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 7 | ||||
-rw-r--r-- | src/microhttpd/response.c | 3 | ||||
-rw-r--r-- | src/microhttpd/test_upgrade.c | 2 | ||||
-rw-r--r-- | src/microhttpd/test_upgrade_ssl.c | 8 |
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; | |||
126 | * Current version of the library. | 126 | * Current version of the library. |
127 | * 0x01093001 = 1.9.30-1. | 127 | * 0x01093001 = 1.9.30-1. |
128 | */ | 128 | */ |
129 | #define MHD_VERSION 0x00095204 | 129 | #define MHD_VERSION 0x00095205 |
130 | 130 | ||
131 | /** | 131 | /** |
132 | * MHD-internal return code for "YES". | 132 | * MHD-internal return code for "YES". |
@@ -686,14 +686,11 @@ enum MHD_FLAG | |||
686 | MHD_USE_TCP_FASTOPEN = 16384, | 686 | MHD_USE_TCP_FASTOPEN = 16384, |
687 | 687 | ||
688 | /** | 688 | /** |
689 | * You need to set this option if you want to use epoll() in | 689 | * You need to set this option if you want to use HTTP "Upgrade". |
690 | * combination with HTTPS connections and switching protocols via | 690 | * "Upgrade" may require usage of additional internal resources, |
691 | * connection upgrades (via #MHD_create_response_for_upgrade()). | 691 | * which we do not want to use unless necessary. |
692 | * This flag is required as under these circumstances we need to | ||
693 | * open up an extra file descriptor, which we do not want to do | ||
694 | * unless necessary. | ||
695 | */ | 692 | */ |
696 | MHD_USE_TLS_EPOLL_UPGRADE = 32768 | MHD_USE_SUSPEND_RESUME | MHD_USE_EPOLL | MHD_USE_TLS | 693 | MHD_ALLOW_UPGRADE = 32768 |
697 | 694 | ||
698 | }; | 695 | }; |
699 | 696 | ||
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, | |||
3437 | (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) ) | 3437 | (MHD_CONNECTION_FOOTERS_RECEIVED != connection->state) ) ) |
3438 | return MHD_NO; | 3438 | return MHD_NO; |
3439 | daemon = connection->daemon; | 3439 | daemon = connection->daemon; |
3440 | if ( (MHD_HTTP_SWITCHING_PROTOCOLS != status_code) && | ||
3441 | (NULL != response->upgrade_handler) ) | ||
3442 | { | ||
3443 | #ifdef HAVE_MESSAGES | ||
3444 | MHD_DLOG (daemon, | ||
3445 | _("Application used invalid status code for 'upgrade' response!\n")); | ||
3446 | #endif | ||
3447 | return MHD_NO; | ||
3448 | } | ||
3449 | if ( (NULL != response->upgrade_handler) && | 3440 | if ( (NULL != response->upgrade_handler) && |
3450 | (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 3441 | (0 == (daemon->options & MHD_ALLOW_UPGRADE)) ) |
3451 | (0 == (daemon->options & MHD_USE_SUSPEND_RESUME)) ) | ||
3452 | { | 3442 | { |
3453 | #ifdef HAVE_MESSAGES | 3443 | #ifdef HAVE_MESSAGES |
3454 | MHD_DLOG (daemon, | 3444 | MHD_DLOG (daemon, |
3455 | _("Application attempted 'upgrade' without setting MHD_USE_SUSPEND_RESUME!\n")); | 3445 | _("Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n")); |
3456 | #endif | 3446 | #endif |
3457 | return MHD_NO; | 3447 | return MHD_NO; |
3458 | } | 3448 | } |
3459 | if ( (NULL != response->upgrade_handler) && | 3449 | if ( (MHD_HTTP_SWITCHING_PROTOCOLS != status_code) && |
3460 | (0 != (MHD_USE_EPOLL & daemon->options)) && | 3450 | (NULL != response->upgrade_handler) ) |
3461 | (0 != (MHD_USE_TLS & daemon->options)) && | ||
3462 | (MHD_USE_TLS_EPOLL_UPGRADE != (MHD_USE_TLS_EPOLL_UPGRADE & daemon->options)) ) | ||
3463 | { | 3451 | { |
3464 | #ifdef HAVE_MESSAGES | 3452 | #ifdef HAVE_MESSAGES |
3465 | MHD_DLOG (daemon, | 3453 | MHD_DLOG (daemon, |
3466 | _("Application attempted 'upgrade' HTTPS connection in epoll mode without setting MHD_USE_HTTPS_EPOLL_UPGRADE!\n")); | 3454 | _("Application used invalid status code for 'upgrade' response!\n")); |
3467 | #endif | 3455 | #endif |
3468 | return MHD_NO; | 3456 | return MHD_NO; |
3469 | } | 3457 | } |
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) | |||
4604 | if (-1 == daemon->epoll_fd) | 4604 | if (-1 == daemon->epoll_fd) |
4605 | return MHD_NO; | 4605 | return MHD_NO; |
4606 | #if HTTPS_SUPPORT | 4606 | #if HTTPS_SUPPORT |
4607 | if (MHD_USE_TLS_EPOLL_UPGRADE == (MHD_USE_TLS_EPOLL_UPGRADE & daemon->options)) | 4607 | if (0 != (MHD_ALLOW_UPGRADE & daemon->options)) |
4608 | { | 4608 | { |
4609 | daemon->epoll_upgrade_fd = setup_epoll_fd (daemon); | 4609 | daemon->epoll_upgrade_fd = setup_epoll_fd (daemon); |
4610 | if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd) | 4610 | if (MHD_INVALID_SOCKET == daemon->epoll_upgrade_fd) |
@@ -4751,6 +4751,11 @@ MHD_start_daemon_va (unsigned int flags, | |||
4751 | daemon->custom_error_log = (MHD_LogCallback) &vfprintf; | 4751 | daemon->custom_error_log = (MHD_LogCallback) &vfprintf; |
4752 | daemon->custom_error_log_cls = stderr; | 4752 | daemon->custom_error_log_cls = stderr; |
4753 | #endif | 4753 | #endif |
4754 | if (0 != (daemon->options & MHD_ALLOW_UPGRADE)) | ||
4755 | { | ||
4756 | daemon->options |= MHD_USE_SUSPEND_RESUME; | ||
4757 | flags |= MHD_USE_SUSPEND_RESUME; | ||
4758 | } | ||
4754 | #ifdef HAVE_LISTEN_SHUTDOWN | 4759 | #ifdef HAVE_LISTEN_SHUTDOWN |
4755 | use_itc = (0 != (daemon->options & (MHD_USE_NO_LISTEN_SOCKET | MHD_USE_ITC))); | 4760 | use_itc = (0 != (daemon->options & (MHD_USE_NO_LISTEN_SOCKET | MHD_USE_ITC))); |
4756 | #else | 4761 | #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, | |||
691 | struct MHD_UpgradeResponseHandle *urh; | 691 | struct MHD_UpgradeResponseHandle *urh; |
692 | size_t rbo; | 692 | size_t rbo; |
693 | 693 | ||
694 | if (0 == (daemon->options & MHD_ALLOW_UPGRADE)) | ||
695 | return MHD_NO; | ||
696 | |||
694 | if (NULL == | 697 | if (NULL == |
695 | MHD_get_response_header (response, | 698 | MHD_get_response_header (response, |
696 | MHD_HTTP_HEADER_UPGRADE)) | 699 | 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, | |||
61 | 61 | ||
62 | done = 0; | 62 | done = 0; |
63 | 63 | ||
64 | d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_USE_SUSPEND_RESUME, | 64 | d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_ALLOW_UPGRADE, |
65 | 1080, | 65 | 1080, |
66 | NULL, NULL, | 66 | NULL, NULL, |
67 | &ahc_upgrade, NULL, | 67 | &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, | |||
139 | 139 | ||
140 | done = 0; | 140 | done = 0; |
141 | 141 | ||
142 | d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_USE_SUSPEND_RESUME |MHD_USE_TLS, | 142 | d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_ALLOW_UPGRADE | MHD_USE_TLS, |
143 | 1080, | 143 | 1080, |
144 | NULL, NULL, | 144 | NULL, NULL, |
145 | &ahc_upgrade, NULL, | 145 | &ahc_upgrade, NULL, |
@@ -198,7 +198,7 @@ main (int argc, | |||
198 | error_count += test_upgrade (0, | 198 | error_count += test_upgrade (0, |
199 | 0); | 199 | 0); |
200 | #ifdef EPOLL_SUPPORT | 200 | #ifdef EPOLL_SUPPORT |
201 | error_count += test_upgrade (MHD_USE_TLS_EPOLL_UPGRADE, | 201 | error_count += test_upgrade (MHD_USE_EPOLL | MHD_USE_TLS, |
202 | 0); | 202 | 0); |
203 | #endif | 203 | #endif |
204 | 204 | ||
@@ -221,10 +221,10 @@ main (int argc, | |||
221 | #endif | 221 | #endif |
222 | #ifdef EPOLL_SUPPORT | 222 | #ifdef EPOLL_SUPPORT |
223 | error_count += test_upgrade (MHD_USE_EPOLL_INTERNALLY | | 223 | error_count += test_upgrade (MHD_USE_EPOLL_INTERNALLY | |
224 | MHD_USE_TLS_EPOLL_UPGRADE, | 224 | MHD_USE_TLS, |
225 | 0); | 225 | 0); |
226 | error_count += test_upgrade (MHD_USE_EPOLL_INTERNALLY | | 226 | error_count += test_upgrade (MHD_USE_EPOLL_INTERNALLY | |
227 | MHD_USE_TLS_EPOLL_UPGRADE, | 227 | MHD_USE_TLS, |
228 | 2); | 228 | 2); |
229 | #endif | 229 | #endif |
230 | /* report result */ | 230 | /* report result */ |