#19098 [Opn]: header("Content-type: text/plain") does not work
| From: | michael dot mauch at gmx dot de | Date: | Wed, 28 Aug 2002 20:52:05 +0000 |
| Subject: | #19098 [Opn]: header("Content-type: text/plain") does not work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-18085@lists.php.net to get a copy of this message | ||
ID: 19098
User updated by: michael.mauch@gmx.de
Reported By: michael.mauch@gmx.de
Status: Open
-Bug Type: Apache related
+Bug Type: HTTP related
Operating System: Linux
-PHP Version: 4CVS-2002-08-27
+PHP Version: 4CVS-2002-08-28
New Comment:
Ok, so you wanted me to get my hands dirty? I had a look at the code
and suggest that it certainly would be a good idea to append the
default charset in sapi_apply_default_charset():
--- php4-STABLE-200208281200/main/SAPI.c~ Sat Jul 27 15:17:37 2002
+++ php4-STABLE-200208281200/main/SAPI.c Wed Aug 28 22:27:20 2002
@@ -261,6 +261,7 @@
newtype = emalloc(newlen + 1);
PHP_STRLCPY(newtype, *mimetype, newlen + 1, len);
strlcat(newtype, ";charset=", newlen + 1);
+ strlcat(newtype, charset, newlen + 1);
if (*mimetype != NULL) {
efree(*mimetype);
}
But that is only a part of the problem. In sapi_add_header_ex(), I see
the lines:
colon_offset = strchr(newheader, ':');
*colon_offset = '\0';
These lines insert a NUL at the colon's position, but I can't see
what's their purpose.
I changed the bug's category from Apache related to HTTP related
because it's certainly not Apache's fault, as it happens in the
standalone php-cgi as well.
Previous Comments:
------------------------------------------------------------------------
[2002-08-27 14:14:38] michael.mauch@gmx.de
I just found out that the php-cgi adds an empty charset, if I don't set
it:
# echo '<? header("Content-type: text/xml");?>' | php-cgi
Status: 200
X-Powered-By: PHP/4.3.0-dev
Content-type text/xml;charset=
If I set the charset (even an empty one), mod_php _does_ send the
Content-type header.
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1>:
| When no explicit charset parameter is provided by the
| sender, media subtypes of the "text" type are defined to
| have a default charset value of "ISO-8859-1" when
| received via HTTP.
So I think I should be allowed to set no charset.
Oh: if I disable the default_charset = "iso-8859-1" in php.ini, it
works just like it should, i.e. I can omit the charset and the
text/plain or text/xml header is sent.
------------------------------------------------------------------------
[2002-08-25 19:15:00] michael.mauch@gmx.de
With php4-STABLE-200208251500 and php4-200208251500 the header function
does not set the Content-type if it is text/xml or text/plain or
text/something.
It works with application/xml, and it works with php-4.2.2.
# HEAD http://localhost/~elmicha/php/header_xml.php
200 OK
Connection: close
Date: Sun, 25 Aug 2002 22:47:51 GMT
Server: Apache/1.3.26 (Unix) mod_perl/1.26 PHP/4.2.2
Content-Type: text/xml
Client-Date: Sun, 25 Aug 2002 22:47:51 GMT
Client-Response-Num: 1
X-Powered-By: PHP/4.2.2
# HEAD http://localhost/~elmicha/php/header_xml.php
200 OK
Connection: close
Date: Sun, 25 Aug 2002 22:48:43 GMT
Server: Apache/1.3.26 (Unix) mod_perl/1.26 PHP/4.2.3-dev
Content-Type: text/html; charset=iso-8859-1
Client-Date: Sun, 25 Aug 2002 22:48:43 GMT
Client-Response-Num: 1
X-Powered-By: PHP/4.2.3-dev
I configured both versions only --with-apxs. The test file:
<?php
header("Content-type: text/xml");
echo "<hello></hello>\n";
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=19098&edit=1