Skip to content
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

[Curl] Add \r\n to HTTP status and headers to mimic what curl does #294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

clemherreman
Copy link

Context

When returning the array of cURL raw headers, PHP-VCR returns them like this

[
    "Content-Type: text/html; charset=UTF-8",
    "Content-Encoding: gzip",
]

However, cURL returns them more "raw", with the trailing \r\n mandatory at the end of every HTTP header line:

[
    "Content-Type: text/html; charset=UTF-8\r\n",
    "Content-Encoding: gzip\r\n",
]

This PR changes the PHP-VCR behavior. This is necessary to HTTP clients, like Symfony HTTP Client that rely on those \r\n to detect the end of the headers and the beginning of the request body, when parsing it. (or just to extract it via substr())

What has been done

VCR/Util/HttpUtil:formatHeadersForCurl() and VCR/Util/HttpUtil:formatAsStatusString() now returns a trailing \r\n to the HTTP status and HTTP header strings.

This is the actual PHP cURL behavior.

Note: This could, however be a BC change if someone was relying on not having those \r\n. However, it would then break in actual cURL requests, so I doubt that it is the case.

How to test

Unit tests were updated.

clemherreman added a commit to clemherreman/php-vcr that referenced this pull request Jan 24, 2020
Merge remote-tracking branch 'origin/fix-http-header-line-feed-missing'
@clemherreman clemherreman force-pushed the fix-http-header-line-feed-missing branch from 642c21f to 6dd0af7 Compare January 24, 2020 14:48
clemherreman added a commit to clemherreman/php-vcr that referenced this pull request Jan 24, 2020
[Curl] Add \r\n to HTTP status and headers to mimic what curl does
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.

None yet

1 participant