[HttpFoundation] Fixed messed up headers
merged branch SamsonIT/fixedMessedUpHeaders (PR #7189)

This PR was squashed before being merged into the 2.2 branch (closes #7189).

Commits
-------

850bd5a [HttpFoundation] Fixed messed up headers

Discussion
----------

[HttpFoundation] Fixed messed up headers

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

I ran into this when somewhere in our code the Response object was cast into a string. After that, when send()'ing the Response, the headers would be all mixed up. This is because the __toString in HeaderBag ksorts the headers, while the __toString in ResponseHeaderBag doesn't ksort the corresponding headerNames. This patch ksorts that one as well.

allPreserveCase() is new to 2.2, so this bug doesn't seem to affect earlier versions.

To be exact, this is where it got introduced: https://github.com/symfony/symfony/commit/63a228c45613bb

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

by Burgov at 2013-02-26T09:27:20Z

B.t.w. another option was to ksort a copy of the headers array in the ResponseBag and leaving the actual thing as-is. Not sure which one would be the best option?