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

Skip to content

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

Open
clemherreman wants to merge 1 commit intophp-vcr:masterfrom
clemherreman:fix-http-header-line-feed-missing
Open

[Curl] Add \r\n to HTTP status and headers to mimic what curl does#294
clemherreman wants to merge 1 commit intophp-vcr:masterfrom
clemherreman:fix-http-header-line-feed-missing

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.

1 participant