[Solar-talk] Solar_Http_Response and check-headers-sent
Paul M Jones
pmjones at ciaweb.net
Fri Jun 1 09:56:40 PDT 2007
On Jun 1, 2007, at 11:50 AM, Antti Holvikari wrote:
> On 6/1/07, Paul M Jones <pmjones at ciaweb.net> wrote:
>> Hey Antti:
>>
>> Regarding the report at <http://solarphp.com/trac/ticket/74> --
>>
>>> I'm Using Solar_http_*Request* in console (think webservices or
>>> something
>>> like that) which returns a Solar_Http_Response when I do a fetch
>>> (). If I
>>> echo something to the screen *before* I do the fetch() (which
>>> tries to
>>> setHeader() for the *response* when it gets a response) I get a
>>> ERR_HEADERS_SENT error. This is because S_H_Response uses
>>> headers_sent()
>>> internally, which should have nothing to do with my console script.
>>> Obviously a check to headers_sent() is needed by Solar when
>>> sending a
>>> normal response back to browser (normal use).
>>>
>>> One solution would be to check for headers_sent() only when
>>> sending a
>>> response to a browser and otherwise just always allow setHeader().
>>> Maybe
>>> add a Solar_Response class for Solar internal use (like
>>> Solar_Request).
>>
>> Let me make sure I understand: You're working at the command line,
>> and you're going to echo the Solar_Http_Response to the command line,
>> so of course the headers aren't going to be part of the output
>> (wouldn't make sense).
>>
>> If that's correct, then it would make sense for Request and Response
>> to be aware that you're at the CLI and not check headers_sent() in
>> that case.
>>
>> Would that help?
>
> Nope :(.
>
> It has nothing to do with CLI per se. It can be a normal php_mod
> request too but usually we don't echo anything *before* we make a
> request with S_H_R. ok, here's an example:
>
> // echo *before* we get a new response
> echo "I send the headers.";
>
> $req = Solar::factory('Solar_Http_Request');
>
> // ...set uris and stuff for request object...
>
> // this will create a response object and try to set
> // headers which will fail because of the first echo
> $res = $req->fetch();
>
> hope this helps...
It helps describe the situation, thanks. :-)
So in this particular case, you don't care if the headers don't get
set, and you don't want Response to throw an exception because the
headers don't matter in this case.
Or, is it that you think Response::setHeader() shouldn't care if
headers have already been sent? (I can see a good case for this.)
If so, do you think there should be notification from Response at any
time, when headers have already been sent?
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list