-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookies and headers are sent twice #15334
Comments
I have encountered the same situation and will send cookies twice |
I am going to use the old cliche this is not a bug it is a feature The majority of applications I have seen and developed, I was expecting the call to It appears your workflow is different and you are in need of sending headers and cookies at a later time. To change the default behavior you can do this: <?php
$response = $application
->sendCookiesOnHandleRequest(false)
->sendHeadersOnHandleRequest(true)
->handle()
;
$response->send(); |
If you expect and design the system to send headers & cookies on handle(), then you should not send headers & cookies on $response->send(). At least not by default. From my experience "send" means "send" and "handle" doesn't mean "send" :) Method names should be self explained. |
How things are and how they should be in terms of verbiage is a long discussion. The code in question was written back in 2013 and hardly touched since. I cannot remember a reference of this or something similar honestly. However digging through the code I see the following: Response -> send (https://github.com/phalcon/cphalcon/blob/5.0.x/phalcon/Http/Response.zep#L334)
Application - handle
The code seems OK to be honest. The check is if headers are sent and then it will send cookies/headers back. I am not sure why you get duplicates. Could you offer an example so that at least we can figure out why this is happening? |
I see that you use headers_sent which becomes true only when actual content is sent. <?php
header('Something: something');
var_dump(headers_list(), headers_sent());
?> Result for me is:
As you see headers_sent() returns false even I try to send header before. In your case it doesnt to prevent to send headers, cookies twice because no actual content is sent. |
Honestly this is the first time I see this. I was under the impression that the What is really going on here - again from what I understand seeing your example, is that somewhere in the code some headers/cookies are being set. The output has not started yet Then at some point the Finally output starts and then you have the duplicate headers. I really don't know how I can get this to not send stuff twice. Looking at the cookies, we could check the For the headers it might be a bit easier since we can query the Thoughts? |
Discussed the issue offline and a solution was found. PR to follow |
Resolved in #15429 Thank you @DestinyMKas and @bin20060407 |
$application->handle() by default sends cookies and headers
https://github.com/phalcon/cphalcon/blob/master/phalcon/Mvc/Application.zep#L393-L405
I use following logic in my code:
In this case cookies and headers are sent twice.
My suggestions would be:
The text was updated successfully, but these errors were encountered: