WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 20 months ago

Last modified 20 months ago

#2567 closed defect (bug) (wontfix)

XML-RPC returns incorrect content length header when using metaWeblog.getRecentPosts

Reported by: dasher@… Owned by:
Milestone: Priority: normal
Severity: major Version: 1.5
Component: XML-RPC Keywords: xml-rpc
Focuses: Cc:

Description

metaWeblog.getRecentPosts returns an incorrect content-length header on WordPress Mu (wordpress.com).

I'll attach a dump of the response to this ticket (if it allows me to).

Attachments (3)

8c814def95a8a82-response-3cebadec-41a4-468e-90f1-122ed4ec87ef.xml (87.6 KB) - added by dasher@… 8 years ago.
Dump of the response when calling metaWeblog.getRecentPosts with a postcount of 40
143_Response.txt (87.8 KB) - added by dasher@… 8 years ago.
Sorry - previous attachment didn't include the headers
bad-content-length.txt (15.6 KB) - added by wonderboymusic 2 years ago.
Content returned truncated

Download all attachments as: .zip

Change History (15)

dasher@…8 years ago

Dump of the response when calling metaWeblog.getRecentPosts with a postcount of 40

dasher@…8 years ago

Sorry - previous attachment didn't include the headers

comment:1 westi8 years ago

  • Keywords bg|reporter-feedback added

The content-length is returned by IXR based on strlen($xml) in class-IXR.php:

 354      function output($xml) {
 355          $xml = '<?xml version="1.0"?>'."\n".$xml;
 356          $length = strlen($xml);
 357          header('Connection: close');
 358          header('Content-Length: '.$length);
 359          header('Content-Type: text/xml');
 360          header('Date: '.date('r'));
 361          echo $xml;
 362          exit;
 363      }

Not sure how this could fail to return the correct content-length - we could of course remove the content-length header as it is not required.

What content-length are you expecting to be returned in this case.

comment:2 dasher@…8 years ago

The second attachment (143_response) contains the full response (headers and data).
The content length advertised is about 800 bytes out.

comment:3 dasher@…8 years ago

Removing the content-length header fixes the problem.

comment:4 foolswisdom8 years ago

Dasher is this still a problem in the official tree?

comment:5 foolswisdom8 years ago

  • Keywords xml-rpc added; bg|reporter-feedback removed
  • Priority changed from highest to normal
  • Resolution set to worksforme
  • Status changed from new to closed
  • Summary changed from XMLRPC returns incorrect content length header when using metaWeblog.getRecentPosts to XML-RPC returns incorrect content length header when using metaWeblog.getRecentPosts

Closing WORKSFORME without testing.
No response to my question above.

comment:6 follow-up: wonderboymusic2 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

This is a problem for me as well - I just imported a bunch of "legacy" content from our old CMS and am getting the wrong content-length when I return content that has a bunch of JavaScript and CSS in it - gross, I know. The XML-RPC requests work when I debug in PHP code, but they break in Java code when the response are returned with wrong Content-Length, typically 12 characters less than actually exist.

Seems like the list of headers should be filterable

comment:7 SergeyBiryukov2 years ago

  • Milestone set to Awaiting Review

comment:8 in reply to: ↑ 6 westi2 years ago

  • Keywords WPMU removed

Replying to wonderboymusic:

This is a problem for me as well - I just imported a bunch of "legacy" content from our old CMS and am getting the wrong content-length when I return content that has a bunch of JavaScript and CSS in it - gross, I know. The XML-RPC requests work when I debug in PHP code, but they break in Java code when the response are returned with wrong Content-Length, typically 12 characters less than actually exist.

Seems like the list of headers should be filterable

Could you provide an example (redacted if necessary) post content that can be used to reproduce this error?

wonderboymusic2 years ago

Content returned truncated

comment:9 wonderboymusic20 months ago

  • Resolution set to wontfix
  • Status changed from reopened to closed

This shouldn't be fixed in class-IXR.php - you should fix it by subclassing wp_xmlrpc_server which extends IXR_Server:

include_once( ABSPATH . WPINC . '/class-IXR.php' );
include_once( ABSPATH . WPINC . '/class-wp-xmlrpc-server.php' );

add_filter( 'wp_xmlrpc_server_class', function () {
	return 'eMusic_XMLRPC_Server';
} );

class eMusic_XMLRPC_Server extends wp_xmlrpc_server {
	function __construct() {
		parent::__construct();
	}

	function output( $xml ) {
                $xml = '<?xml version="1.0"?>' . PHP_EOL . $xml;
                header( 'Connection: close' );
                header( 'Content-Type: text/xml' );
                header( 'Date: ' . date( 'r' ) );
                echo $xml;
                exit();
        }
}

comment:10 markoheijnen20 months ago

Is the fix only to add: header( 'Connection: close' );?

comment:11 wonderboymusic20 months ago

No, removing the Content-Length header - here's the original:

    function output($xml)
    {
        $xml = '<?xml version="1.0"?>'."\n".$xml;
        $length = strlen($xml);
        header('Connection: close');
        header('Content-Length: '.$length);
        header('Content-Type: text/xml');
        header('Date: '.date('r'));
        echo $xml;
        exit;
    }

comment:12 SergeyBiryukov20 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.