-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Ability to unset a default header added by HttpKernelBrowser / Client #33393
Comments
this behavior change has been fixed, so that API Platform tests should now be alright, isn't it? |
Our test suite is fixed, yes, as we've implemented further workarounds. However, the design problem remains. There is no way for the user to unset any of these default headers when they're using the It's very bad for DX when you don't have full control over the HTTP client you're using. The limitations are understandable if you're working with an actual browser, but it's not the case here. We should aim for feature parity with |
"Very bad" is very subjective. What you can use today is the best the community achieved so far, thanks to them. About the future: PR welcome as usual :) |
Sorry if my comment came off as diminishing the work of the community. That was not my intention. What I mean is, this is a feature request. 😄 |
For the record, API Platform is bite by this problem again. Our workaround doesn't work anymore because typehints have been added: https://github.com/api-platform/core/blob/89c0f30d188b0ff4f15302d1ee901353417663e3/features/bootstrap/HttpHeaderContext.php#L35 |
Symfony version(s) affected: 3.4+
Description
There is currently no way to unset a HTTP request header through the BrowserKit
AbstractBrowser
/Client
. This was requested before in #20306, but actually implementing anunsetServerParameter
method would not help in our case.The problem we're facing here (in API Platform) is that when we send a request using
HttpKernelBrowser
/Client
:symfony/src/Symfony/Component/HttpKernel/Client.php
Lines 136 to 138 in f1edae0
it calls (HttpFoundation)
Request::create
which adds some default request headers:symfony/src/Symfony/Component/HttpFoundation/Request.php
Lines 309 to 324 in f1edae0
This includes the
Accept
header, which we need to be able to remove in order to test content negotiation scenarios where the client doesn't send theAccept
header, thereby resulting in the use of the default media type.How to reproduce
We had been using a workaround to unset the
Accept
header in our test suite, basically:The end result in the
HeaderBag
is:However, fixes in
HeaderBag::get
, specifically the change made to this line:symfony/src/Symfony/Component/HttpFoundation/HeaderBag.php
Line 124 in f1edae0
means that we get an empty string now instead of
null
.Possible Solution
So this breaks our test suite. We could find new workarounds, including checking for the case where the
Accept
header is an empty string (weird!), or overriding / extending some parts of the chain which sends the request in our test suite.However, we're wondering if there might be a better way of fixing this for everyone. It was an ugly workaround in the first place.
This problem also affects
ApiTestCase
in API Platform, as the user would be unable to send a request without any of the default headers.Additional context
The text was updated successfully, but these errors were encountered: