#2567 closed defect (bug) (fixed)
XML-RPC returns incorrect content length header when using metaWeblog.getRecentPosts
Reported by: | Owned by: | 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)
Change History (27)
#1
@
19 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
@
19 years ago
The second attachment (143_response) contains the full response (headers and data).
The content length advertised is about 800 bytes out.
#5
@
18 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:
↓ 8
@
13 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
#8
in reply to:
↑ 6
@
13 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?
#9
@
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(); } }
#11
@
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; }
This ticket was mentioned in Slack in #core by wpdavis. View the logs.
9 years ago
#14
@
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.
#16
@
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.
#19
@
9 years ago
This feels like something might be compressing the response (plugin, php, or server) and not overriding the Content-Length header specified.
Dump of the response when calling metaWeblog.getRecentPosts with a postcount of 40