Home » Web Services » XML_RPC » Bug #6007
Server fails to set Content-Type
Details
| Submitted | 2005-11-18 00:53 UTC |
|---|---|
| From | asppsa at gmail dot com |
| Assigned | danielc |
| Status | Closed |
| Package | XML_RPC |
| PHP Version | 5.0.4 |
| OS | NetBSD |
| Roadmaps | (Not assigned) |
Comments
[2005-11-18 00:53 UTC] asppsa at gmail dot com
Description:
------------
When the XML-RPC server returns a result the Content-Type header is set to the default 'text/html'.
It appears that the XML_RPC_Server code uses one string to set all the headers at once. This doesn't appear to work. If one manually sets it (see below), however, then it does.
The Content Length is set properly, so it looks like only the first line of the header string gets accepted by header().
Test script:
---------------
<?php
$server = new XML_RPC_Server (array (
'somefunc' => array ('function' => 'funcname')
));
?>
--- If I change it like so, it works (produces the 'expected result' below): ---
<?php
header ('Content-Type: text/xml');
$server = new XML_RPC_Server (array (
'somefunc' => array ('function' => 'funcname')
));
?>
Expected result:
----------------
(When accessed via the XML_RPC_Client with setDebug (1))
---GOT---
HTTP/1.1 200 OK
Date: Fri, 18 Nov 2005 00:33:09 GMT
Server: Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7g-fips DAV/2 PHP/5.0.4
X-Powered-By: PHP/5.0.4
Content-Length: 4951
Connection: close
Content-Type: text/xml
...
(maybe it should include the charset too?)
Actual result:
--------------
---GOT---
HTTP/1.1 200 OK
Date: Fri, 18 Nov 2005 00:47:56 GMT
Server: Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7g-fips DAV/2 PHP/5.0.4
X-Powered-By: PHP/5.0.4
Content-Length: 4951
Connection: close
Content-Type: text/html
...
[2005-11-18 03:33 UTC] asppsa at gmail dot com
I have (hopefully) fixed this
Here is a diff ...
394c394,397
< header($this->server_headers);
---
> foreach ($this->server_headers as $h)
> {
> header($h);
> }
429,432c432,436
< $this->server_headers = 'Content-Length: '
< . strlen($this->server_payload) . "\r\n"
< . 'Content-Type: text/xml;'
< . ' charset=' . $this->encoding;
---
> $this->server_headers = array (
> 'Content-Length: ' . strlen($this->server_payload),
> 'Content-Type: text/xml; charset=' . $this->encoding
> );
>
--- END ---
cheers,
Alastair
[2005-11-20 20:31 UTC] asppsa at gmail dot com
Do you think it would be better for backward compatibility if we were to keep the $server_headers variable as a string, and just split it on "/\r\n|\n\r/" or something similar? That way it won't break for people who have added to or altered the string themselves ...
Sorry about the non-standard/incomplete patch. I've had a look around for information on how one is supposed to use the header() function, and haven't seen any examples where multiple headers are set with a single call, so I'm definitely quite happy to spend the time to make the server package more compliant, hopefully without breaking any backward compatibility!
Let me know what you think,
-Alastair