# problem with header() and php trunk

- Thread: https://externals.io/message/51533
- Original archive: https://news-web.php.net/php.internals/51533
- Started by Carsten Wiedmann on 2011-02-24T16:28:18+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #51533 — Carsten Wiedmann — 2011-02-24T16:28:18+00:00

URL: https://externals.io/message/51533#51533

Hi list,

this code is not working with the current trunk:
| <?php
| header('Content-Language: ');
| ?>

The result is an internale server error:
| [Thu Feb 24 17:21:25 2011] [error] [client ::1] malformed header from
| script. Bad header=Content-Language: php-cgi.exe


Without only a space after ":"
| header('Content-Language:');
or
| header('Content-Language: en-US');
it's working.


Regards,
Carsten

---

## #51534 — Carsten Wiedmann — 2011-02-24T22:56:47+00:00

URL: https://externals.io/message/51533#51534 · In reply to: #51533

> 
> > […]
>
> I don't think this is a PHP problem. Everything in the error message
> indicates to me that PHP is doing what you told it to do, and the
> webserver doesn't like it (for whatever reason). This is either your
> fault, or the webserver's fault, and I don't see why PHP should
> compensate for it.
>
> Ben.

Oh, this only happens with trunk, but not with e.g 5.3.5. But just see 
the difference:

test.php
| <?php
| header('Content-Language: ');
| ?>

That's what PHP 5.3.5 is sending to the server:
| X-Powered-By: PHP/5.3.5
| Content-Language:
| Content-type: text/html

And that's what PHP trunk is sending to the server:
| X-Powered-By: PHP/5.3.99-dev
| Content-Language
| Content-type: text/html

see the missing ":" after the header name.

if I'm using this script:
test.php
| <?php
| header('Content-Language:');
| ?>

the output is correct:
| X-Powered-By: PHP/5.3.99-dev
| Content-Language:
| Content-type: text/html


Regards,
Carsten

---

## #51535 — Carsten Wiedmann — 2011-02-25T10:36:12+00:00

URL: https://externals.io/message/51533#51535 · In reply to: #51534

Am 24.02.2011 23:56, schrieb Carsten Wiedmann:
> Oh, this only happens with trunk, but not with e.g 5.3.5. But just see
> the difference:

OK, this bug was introduced in r301263. It's removing +1 char while 
cutting LWS at the end of a header line.

<<<PATCH
Index: SAPI.c
===================================================================
--- SAPI.c	(Revision 308566)
+++ SAPI.c	(Arbeitskopie)
@@ -680,7 +680,7 @@
  		do {
  			header_line_len--;
  		} while(header_line_len && isspace(header_line[header_line_len-1]));
-		header_line[--header_line_len]='\0';
+		header_line[header_line_len]='\0';
  	}
  	
  	if (op == SAPI_HEADER_DELETE) {
PATCH;

<<<TESTPHPT
--TEST--
 `header()` function - LWS at end of field-value
--GET--

--FILE--
<?php
header('x-headertest: foo ');
var_dump(headers_list());
?>
--EXPECTREGEX--
.*string\(17\) \"x-headertest: foo\".*
TESTPHPT;


BTW:
PHP is removing LWS at the end of the field-value, but why is it not 
replacing LWS between the field-name: and field-value with one SP?

Regards,
Carsten

---

## #51536 — Pierre Joye — 2011-02-25T11:29:01+00:00

URL: https://externals.io/message/51533#51536 · In reply to: #51535

hi Carsten,

Thanks for the report and the patch (applied)!

Cheers,


> Am 24.02.2011 23:56, schrieb Carsten Wiedmann:
> > […]
>
> OK, this bug was introduced in r301263. It's removing +1 char while cutting
> LWS at the end of a header line.
>
> <<<PATCH
> Index: SAPI.c
> ===================================================================
> --- SAPI.c      (Revision 308566)
> +++ SAPI.c      (Arbeitskopie)
> @@ -680,7 +680,7 @@
>                do {
>                        header_line_len--;
>                } while(header_line_len &&
> isspace(header_line[header_line_len-1]));
> -               header_line[--header_line_len]='\0';
> +               header_line[header_line_len]='\0';
>        }
>
>        if (op == SAPI_HEADER_DELETE) {
> PATCH;
>
> <<<TESTPHPT
> --TEST--
> `header()` function - LWS at end of field-value
> --GET--
>
> --FILE--
> <?php
> header('x-headertest: foo ');
> var_dump(headers_list());
> ?>
> --EXPECTREGEX--
> .*string\(17\) \"x-headertest: foo\".*
> TESTPHPT;
>
>
> BTW:
> PHP is removing LWS at the end of the field-value, but why is it not
> replacing LWS between the field-name: and field-value with one SP?
>
> Regards,
> Carsten
>
>
> --
> 
> 
>
>



-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
