Make WordPress Core

Opened 18 years ago

Closed 8 years ago

Last modified 8 years ago

#2567 closed defect (bug) (fixed)

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

Reported by: dasherinspiredthinkingcouk's profile dasher@… Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: major Version: 1.5
Component: XML-RPC Keywords: xml-rpc has-patch
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 (5)

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

Download all attachments as: .zip

Change History (27)

@dasher@…
18 years ago

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

@dasher@…
18 years ago

Sorry - previous attachment didn't include the headers

#1 @westi
18 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.

#2 @dasher@…
18 years ago

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

#3 @dasher@…
18 years ago

Removing the content-length header fixes the problem.

#4 @foolswisdom
18 years ago

Dasher is this still a problem in the official tree?

#5 @foolswisdom
17 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.

#6 follow-up: @wonderboymusic
12 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

#7 @SergeyBiryukov
12 years ago

  • Milestone set to Awaiting Review

#8 in reply to: ↑ 6 @westi
12 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?

@wonderboymusic
12 years ago

Content returned truncated

#9 @wonderboymusic
12 years 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();
        }
}

#10 @markoheijnen
12 years ago

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

#11 @wonderboymusic
12 years 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;
    }

#12 @SergeyBiryukov
12 years ago

  • Milestone Awaiting Review deleted

This ticket was mentioned in Slack in #core by wpdavis. View the logs.


9 years ago

#14 @wpdavis
9 years ago

  • Keywords has-patch added
  • Resolution wontfix deleted
  • Status changed from closed to reopened

Adding a patch to fix this in core. Just spent quite a while tracking this one back and would like to help others avoid that same unpleasantness if possible.

#15 @SergeyBiryukov
9 years ago

  • Milestone set to Awaiting Review

#16 @wpdavis
9 years ago

fyeyes: Using mbstring_binary_safe_encoding() or calling mb_strlen() directly with a variety of encodings does not seem to return the proper strlen, so there must be something else going on here. Continuing my search. But it seems having no content-length would be massively preferable to an incorrect content-length.

@SergeyBiryukov
9 years ago

#17 @SergeyBiryukov
9 years ago

I was thinking of something like 2567.diff. Does that not work as expected?

#18 @wpdavis
9 years ago

Unfortunately it does not. I'm doing some research as to why.

#19 @dd32
9 years ago

This feels like something might be compressing the response (plugin, php, or server) and not overriding the Content-Length header specified.

#20 @wpdavis
9 years ago

@dd32 the header is too short, not too long

#21 @wonderboymusic
8 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from reopened to closed

In 34571:

XML-RPC: IXR_Server::output() is notoriously bad at returning the right value for the Content-Length HTTP header. This header is not required, so we will remove it.

"We could of course remove the content-length header as it is not required" was suggested 10 years ago. The IXR library is not maintained. Our release is the latest, which occurred in 2010.

Fixes #2567.

#22 @netweb
8 years ago

  • Milestone changed from Awaiting Review to 4.4
Note: See TracTickets for help on using tickets.