aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r--src/microhttpd/connection.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index ff7f663f..b1b34cef 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -736,7 +736,8 @@ keepalive_possible (struct MHD_Connection *connection)
736 if (NULL == end) 736 if (NULL == end)
737 return MHD_YES; 737 return MHD_YES;
738 if ( (MHD_str_equal_caseless_ (end, "close")) || 738 if ( (MHD_str_equal_caseless_ (end, "close")) ||
739 (MHD_str_equal_caseless_ (end, "upgrade")) ) 739 ( (MHD_str_equal_caseless_ (end, "upgrade")) &&
740 (NULL == connection->response->upgrade_handler) ) )
740 return MHD_NO; 741 return MHD_NO;
741 return MHD_YES; 742 return MHD_YES;
742 } 743 }
@@ -2222,6 +2223,9 @@ MHD_connection_handle_read (struct MHD_Connection *connection)
2222 break; 2223 break;
2223 case MHD_CONNECTION_CLOSED: 2224 case MHD_CONNECTION_CLOSED:
2224 return MHD_YES; 2225 return MHD_YES;
2226 case MHD_CONNECTION_UPGRADE:
2227 EXTRA_CHECK (0);
2228 break;
2225 default: 2229 default:
2226 /* shrink read buffer to how much is actually used */ 2230 /* shrink read buffer to how much is actually used */
2227 MHD_pool_reallocate (connection->pool, 2231 MHD_pool_reallocate (connection->pool,
@@ -2305,7 +2309,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2305 do_write (connection); 2309 do_write (connection);
2306 if (connection->state != MHD_CONNECTION_HEADERS_SENDING) 2310 if (connection->state != MHD_CONNECTION_HEADERS_SENDING)
2307 break; 2311 break;
2308 check_write_done (connection, MHD_CONNECTION_HEADERS_SENT); 2312 check_write_done (connection,
2313 MHD_CONNECTION_HEADERS_SENT);
2309 break; 2314 break;
2310 case MHD_CONNECTION_HEADERS_SENT: 2315 case MHD_CONNECTION_HEADERS_SENT:
2311 EXTRA_CHECK (0); 2316 EXTRA_CHECK (0);
@@ -2395,6 +2400,9 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2395 case MHD_TLS_CONNECTION_INIT: 2400 case MHD_TLS_CONNECTION_INIT:
2396 EXTRA_CHECK (0); 2401 EXTRA_CHECK (0);
2397 break; 2402 break;
2403 case MHD_CONNECTION_UPGRADE:
2404 EXTRA_CHECK (0);
2405 break;
2398 default: 2406 default:
2399 EXTRA_CHECK (0); 2407 EXTRA_CHECK (0);
2400 CONNECTION_CLOSE_ERROR (connection, 2408 CONNECTION_CLOSE_ERROR (connection,
@@ -2586,9 +2594,9 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2586 } 2594 }
2587 if ( (NULL != connection->response) && 2595 if ( (NULL != connection->response) &&
2588 ( (MHD_str_equal_caseless_ (connection->method, 2596 ( (MHD_str_equal_caseless_ (connection->method,
2589 MHD_HTTP_METHOD_POST)) || 2597 MHD_HTTP_METHOD_POST)) ||
2590 (MHD_str_equal_caseless_ (connection->method, 2598 (MHD_str_equal_caseless_ (connection->method,
2591 MHD_HTTP_METHOD_PUT))) ) 2599 MHD_HTTP_METHOD_PUT))) )
2592 { 2600 {
2593 /* we refused (no upload allowed!) */ 2601 /* we refused (no upload allowed!) */
2594 connection->remaining_upload_size = 0; 2602 connection->remaining_upload_size = 0;
@@ -2722,6 +2730,21 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2722 } 2730 }
2723 else 2731 else
2724 socket_start_normal_buffering (connection); 2732 socket_start_normal_buffering (connection);
2733 if (NULL != connection->response->upgrade_handler)
2734 {
2735 /* This connection is "upgraded". Pass socket to application. */
2736 if (MHD_YES !=
2737 MHD_response_execute_upgrade_ (connection->response,
2738 connection))
2739 {
2740 /* upgrade failed, fail hard */
2741 CONNECTION_CLOSE_ERROR (connection,
2742 NULL);
2743 continue;
2744 }
2745 connection->state = MHD_CONNECTION_UPGRADE;
2746 continue;
2747 }
2725 2748
2726 if (connection->have_chunked_upload) 2749 if (connection->have_chunked_upload)
2727 connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY; 2750 connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY;
@@ -2882,6 +2905,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2882 case MHD_CONNECTION_CLOSED: 2905 case MHD_CONNECTION_CLOSED:
2883 cleanup_connection (connection); 2906 cleanup_connection (connection);
2884 return MHD_NO; 2907 return MHD_NO;
2908 case MHD_CONNECTION_UPGRADE:
2909 return MHD_YES; /* keep open */
2885 default: 2910 default:
2886 EXTRA_CHECK (0); 2911 EXTRA_CHECK (0);
2887 break; 2912 break;