Make WordPress Core

Ticket #41358: end-rest-api-connection-41358.diff

File end-rest-api-connection-41358.diff, 1.3 KB (added by mikejolley, 7 years ago)

Patch for issue 41358

  • wp-includes/rest-api.php

    diff --git wp-includes/rest-api.php wp-includes/rest-api.php
    index 3b158ea07f..32ecb723dc 100644
    function rest_api_loaded() { 
    269269                $route = '/';
    270270        }
    271271        $server->serve_request( $route );
     272        $server->finish_request();
    272273
    273274        // We're done.
    274275        die();
  • wp-includes/rest-api/class-wp-rest-server.php

    diff --git wp-includes/rest-api/class-wp-rest-server.php wp-includes/rest-api/class-wp-rest-server.php
    index c69cb4834c..a7da5393fb 100644
    class WP_REST_Server { 
    414414        }
    415415
    416416        /**
     417         * Handles finishing an API request.
     418         *
     419         * Closes connections, where possible, so the response is sent as soon as possible
     420         * and is not slowed down by functions during shutdown.
     421         *
     422         * @access public
     423         */
     424        public function finish_request() {
     425                if ( is_callable( 'fastcgi_finish_request' ) ) {
     426                        // This function is available on nginx and is the cleanest solution.
     427                        fastcgi_finish_request();
     428
     429                } elseif ( ! headers_sent() ) {
     430                        // For apache, we can send some headers to end the connection early.
     431                        header( 'Content-Length: ' . ob_get_length() );
     432                        header( 'Connection: close' );
     433                        ob_end_flush();
     434                        flush();
     435                }
     436        }
     437
     438        /**
    417439         * Converts a response to data to send.
    418440         *
    419441         * @since 4.4.0