aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-08-01 21:40:47 +0200
committerChristian Grothoff <christian@grothoff.org>2019-08-01 21:40:47 +0200
commit26368ac8f1a32f49eaffae77abcfc595c62802bd (patch)
tree0e444c75bb66730ea96929fda487fbee4e26c41f
parent97fd0a6557b98166f9617370e1497d47e80e9a04 (diff)
downloadlibmicrohttpd-26368ac8f1a32f49eaffae77abcfc595c62802bd.tar.gz
libmicrohttpd-26368ac8f1a32f49eaffae77abcfc595c62802bd.zip
add ways for application to control corking for upgraded sockets
-rw-r--r--src/include/microhttpd.h12
-rw-r--r--src/microhttpd/connection.c2
-rw-r--r--src/microhttpd/response.c38
-rw-r--r--src/microhttpd/test_upgrade.c2
4 files changed, 52 insertions, 2 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index c2fc90a4..00288696 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -3132,7 +3132,17 @@ enum MHD_UpgradeAction
3132 * 3132 *
3133 * Takes no extra arguments. 3133 * Takes no extra arguments.
3134 */ 3134 */
3135 MHD_UPGRADE_ACTION_CLOSE = 0 3135 MHD_UPGRADE_ACTION_CLOSE = 0,
3136
3137 /**
3138 * Enable CORKing on the underlying socket.
3139 */
3140 MHD_UPGRADE_ACTION_CORK_ON = 1,
3141
3142 /**
3143 * Disable CORKing on the underlying socket.
3144 */
3145 MHD_UPGRADE_ACTION_CORK_OFF = 2
3136 3146
3137}; 3147};
3138 3148
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 67ff6017..c2add01a 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3181,7 +3181,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
3181 return; 3181 return;
3182 case MHD_CONNECTION_HEADERS_SENDING: 3182 case MHD_CONNECTION_HEADERS_SENDING:
3183 { 3183 {
3184 const size_t wb_ready =connection->write_buffer_append_offset - 3184 const size_t wb_ready = connection->write_buffer_append_offset -
3185 connection->write_buffer_send_offset; 3185 connection->write_buffer_send_offset;
3186 3186
3187 /* if the response body is not available, we use MHD_send_on_connection_() */ 3187 /* if the response body is not available, we use MHD_send_on_connection_() */
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 7b98a45c..65ea7b09 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -825,6 +825,44 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
825 * be moved to cleanup list by MHD_resume_connection(). */ 825 * be moved to cleanup list by MHD_resume_connection(). */
826 MHD_resume_connection (connection); 826 MHD_resume_connection (connection);
827 return MHD_YES; 827 return MHD_YES;
828 case MHD_UPGRADE_ACTION_CORK_ON:
829 if (connection->sk_cork_on)
830 return MHD_YES;
831#ifdef HTTPS_SUPPORT
832 if (0 != (daemon->options & MHD_USE_TLS) )
833 {
834 gnutls_record_cork (connection->tls_session);
835 connection->sk_cork_on = true;
836 return MHD_YES;
837 }
838 else
839#else
840 {
841 if (0 ==
842 MHD_socket_cork_ (connection->socket_fd,
843 true))
844 connection->sk_cork_on = true;
845 }
846#endif
847 case MHD_UPGRADE_ACTION_CORK_OFF:
848 if (! connection->sk_cork_on)
849 return MHD_YES;
850#ifdef HTTPS_SUPPORT
851 if (0 != (daemon->options & MHD_USE_TLS) )
852 {
853 gnutls_record_uncork (connection->tls_session, 0);
854 connection->sk_cork_on = false;
855 return MHD_YES;
856 }
857 else
858#else
859 {
860 if (0 ==
861 MHD_socket_cork_ (connection->socket_fd,
862 false))
863 connection->sk_cork_on = false;
864 }
865#endif
828 default: 866 default:
829 /* we don't understand this one */ 867 /* we don't understand this one */
830 return MHD_NO; 868 return MHD_NO;
diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c
index caf12e61..9135187c 100644
--- a/src/microhttpd/test_upgrade.c
+++ b/src/microhttpd/test_upgrade.c
@@ -685,6 +685,8 @@ run_usock (void *cls)
685{ 685{
686 struct MHD_UpgradeResponseHandle *urh = cls; 686 struct MHD_UpgradeResponseHandle *urh = cls;
687 687
688 MHD_upgrade_action (urh,
689 MHD_UPGRADE_ACTION_CORK_OFF);
688 send_all (usock, 690 send_all (usock,
689 "Hello"); 691 "Hello");
690 recv_all (usock, 692 recv_all (usock,