Bug #52555 [Com]: Headers_List not returning HTTP Status Code

From: Date: Fri, 06 Aug 2010 12:15:06 +0000
Subject: Bug #52555 [Com]: Headers_List not returning HTTP Status Code
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-153153@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52555&edit=1

 ID:                 52555
 Comment by:         dragoonis@php.net
 Reported by:        dragoonis@php.net
 Summary:            Headers_List not returning HTTP Status Code
 Status:             Bogus
 Type:               Bug
 Package:            *Web Server problem
 PHP Version:        5.3.3
 Assigned To:        dragoonis
 Block user comment: N

 New Comment:

As per IRC conversations, the status_line or http_response_code are not
headers therefore should not be returned from headers_list() so the
conclusion is to make a new function to give you http_response_code. I
will update this ticket with the patch.


Previous Comments:
------------------------------------------------------------------------
[2010-08-06 13:42:58] johannes@php.net

RFC 2616 (Hypertext Transfer Protocol -- HTTP/1.1) makes a difference
between the Status-Line (6.1) and the Headers (6.2) that we allow
setting the Status-Line via header() is kind of a hack, headers_list()
should only list headers so users can work with them easily (like
splitting up at ": " etc.)

------------------------------------------------------------------------
[2010-08-06 12:50:43] dragoonis@php.net

Description:
------------
Ok so i've found the reason why this doesn't work but i'd like feedback
on the appropriate area to change as this looks like it was
intentionally developed this way.

headers_list() gets passed SG(sapi_headers).headers and prints them.
This works however when you do header() -> sapi_header_op() and you set
a response code such as 'HTTP/1.0 404 Not Found'.
It does not put this header into SG(sapi_headers).headers but it puts it
into SG(sapi_headers).http_response_code instead.

This looks to be intentional as there are special functions for updating
the response code such as sapi_update_response_code()

So the end question is, should I modify sapi_header_op() to also include
the response code in SG(sapi_headers).headers or should I modify
headers_list() to receive SG(sapi_headers).headers and
SG(sapi_headers).http_response_code.

I could also make a new function which only returns
SG(sapi_headers).http_response_code but i think that's a waste of time
and could update headers_list() or whatnot. 

FYI: I tested apache_response_headers() and got no http response code in
their either.


Test script:
---------------
<?php

header("Content-type: text/plain");

header('HTTP/1.0 404 Not Found');

var_dump(headers_list()); exit;

Expected result:
----------------
array(3) {
  [0]=>
    string(34) "X-Powered-By: PHP/5.3.2-1ubuntu4.2"
  [1]=>
    string(30) "Content-type: text/plain"
  [2]=>
    string(22) "HTTP/1.0 404 Not Found"
}

Actual result:
--------------
array(2) {
  [0]=>
    string(34) "X-Powered-By: PHP/5.3.2-1ubuntu4.2"
  [1]=>
    string(30) "Content-type: text/plain"
}


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52555&edit=1


Thread (14 messages)

« previous php.bugs (#153153) next »