Thanks to visit codestin.com
Credit goes to github.com

Skip to content

prevent PHP from magically setting a 302 header #9365

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

Merged
merged 1 commit into from
Oct 28, 2013

Conversation

lsmith77
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? yes (for people relying on getting a magic 302 when setting a Location header)
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

this needs a test case .. but first let me know if you are ok with this change.
see http://www.php.net/manual/en/function.header.php

@@ -332,12 +332,12 @@ public function sendHeaders()
}

// status
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), false, $this->statusCode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather keep true for the replace argument (like it was before as true is the default value.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah my bad .. i thought the default was null .. will fix this

@fabpot
Copy link
Member

fabpot commented Oct 24, 2013

👍

@lsmith77
Copy link
Contributor Author

ok .. will look into writing a test case, though I am not sure if this is testable on the CLI ..

@lsmith77
Copy link
Contributor Author

i tried adding a unit test but as I feared it doesn't seem possible and it seems like we do not really have other tests for this either.

I looked a bit on the web and found:
http://stackoverflow.com/questions/9745080/test-php-headers-with-phpunit
http://stackoverflow.com/questions/9127252/phpunit-test-for-expected-headers

but I could not get either of the proposes solutions in the various responses to work and return me all headers.

@lyrixx
Copy link
Member

lyrixx commented Oct 27, 2013

@lsmith77 you can add a functional test for php >= 5.4 (with the build-in php server).

fabpot added a commit that referenced this pull request Oct 28, 2013
This PR was merged into the master branch.

Discussion
----------

prevent PHP from magically setting a 302 header

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | yes (for people relying on getting a magic 302 when setting a Location header)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

this needs a test case .. but first let me know if you are ok with this change.
see http://www.php.net/manual/en/function.header.php

Commits
-------

c140d4f prevent PHP from magically setting a 302 header, see http://www.php.net/manual/en/function.header.php
@fabpot fabpot merged commit c140d4f into symfony:master Oct 28, 2013
@cordoval
Copy link
Contributor

@fabpot this was waiting for the functional tests 👶 I guess that could be on a next PR

@yjv
Copy link

yjv commented Oct 28, 2013

@lsmith77 to test this you can define the header function during you testcase under the Symfony\Component\HttpFoundation namespace and php will use that one instead of the built in one. A bit hacky :) but has worked for me in a pinch

@lsmith77 lsmith77 deleted the prevent_header_magic branch October 28, 2013 15:52
@lsmith77
Copy link
Contributor Author

would not be so useful in this case as we need to test the suppression of magic behavior of PHP.

nicolas-grekas added a commit that referenced this pull request Nov 26, 2015
…ine (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[HttpFoundation] Workaround HHVM rewriting HTTP response line

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16481, #9365
| License       | MIT
| Doc PR        | -

Commits
-------

5013f98 [HttpFoundation] Workaround HHVM rewriting HTTP response line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants