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

[BrowserKit] Raw body with custom Content-Type header #36839

Merged
merged 1 commit into from May 22, 2020

Conversation

azhurb
Copy link
Contributor

@azhurb azhurb commented May 16, 2020

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
License MIT

Currently, if you try to send POST/PUT request with custom Content-Type header and specified body, the real request will contain text/plain content type.

Following code

$client->request(
    'POST',
    '/url',
    [],
    [],
    [
        'CONTENT_TYPE' => 'application/json'
    ],
    '{"foo":"bar"}'
);

produces next request

POST /
Content-Type: text/plain; charset=utf-8

{"foo":"bar"}

With this fix, the request will be

POST /
Content-Type: application/json

{"foo":"bar"}

@ro0NL
Copy link
Contributor

ro0NL commented May 16, 2020

Hi @azhurb, looks like it fixes #36640 :) cool.

WDYT of my patch suggestion in the issue? I believe there are some other cases where we need to preserve the given content-type as well.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks. Here is some nitpicking.

src/Symfony/Component/BrowserKit/HttpBrowser.php Outdated Show resolved Hide resolved
src/Symfony/Component/BrowserKit/HttpBrowser.php Outdated Show resolved Hide resolved
src/Symfony/Component/BrowserKit/HttpBrowser.php Outdated Show resolved Hide resolved
src/Symfony/Component/BrowserKit/HttpBrowser.php Outdated Show resolved Hide resolved
src/Symfony/Component/BrowserKit/HttpBrowser.php Outdated Show resolved Hide resolved
@azhurb
Copy link
Contributor Author

azhurb commented May 16, 2020

Hi @azhurb, looks like it fixes #36640 :) cool.

WDYT of my patch suggestion in the issue? I believe there are some other cases where we need to preserve the given content-type as well.

Hi @ro0NL. Actually I believe we need to preserve content-type only if the raw body data is not empty. It looks like other cases are already covered. Anyway, your patch should work as well :)

@azhurb
Copy link
Contributor Author

azhurb commented May 16, 2020

There is also discussion from 2016 about this issue #20042

@nicolas-grekas nicolas-grekas added this to the 4.4 milestone May 18, 2020
@fabpot
Copy link
Member

fabpot commented May 22, 2020

Thank you @azhurb.

@fabpot fabpot merged commit 6d7c696 into symfony:4.4 May 22, 2020
This was referenced May 26, 2020
kbond added a commit to zenstruck/browser that referenced this pull request Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants