Comments (5)
Ah perfect, that worked! Thanks so much, appreciate it.
from saloon.
Hey @jlevers thats awesome news, nice work on migrating it all over!
Would you be able to show me your defaultHeaders on your request, please? The way it's meant to work is the request's properties will always be merged after the connectors, so that they will always take priority.
I'm wondering if there's either a bug, or an opportunity to introduce a new interface that prevents merging headers, body etc for these use cases.
from saloon.
@jlevers It sounds like your issue might be the same as #398.
Although that issue mentions plugins rather than the Request itself.
Not the most convenient way, but I wonder if you could maybe try adding a middleware as late as possible and modify the PendingRequest that way.
I know @Sammyjo20 already mentions this not working in #398, but maybe try to use a plugin anyway.
Worst case you could maybe add the plugin/middleware on the Connector instead, and check the type of the Request the PendingRequest is for, and, if the correct Request, modify the headers on the PendingRequest.
Edit:
I wonder if it's not enough to just use the boot()
method on the Request, as shown in the middleware link, but just reference the headers directly.
Then unset headers you don't want.
If you're certain that only the specific Requests defaultHeaders()
should be used, you could reset the headers object on the PendingRequest and grab the headers from the Requests defaultHeaders()
method.
from saloon.
@Sammyjo20 thanks for the response :)
I don't have any defaultHeaders()
method defined on the request, because I'm not really trying to overwrite the connector's headers – I just want the connector's headers removed entirely. I tried making the request's default headers return an empty array, but that didn't work.
@juse-less good call, middleware should work. I'd like to avoid that and set the headers in the request class if possible, but if that isn't doable then I'll go the middleware route.
from saloon.
@jlevers typing this on my phone, so bear with me.
I think you could do something like this:
class MyRequest extends Request
{
public function boot(PendingRequest $request): void
{
$defaultHeaders = array_keys($request->getConnector()->headers()->all());
foreach ($defaultHeaders as $defaultHeader) {
$request->headers()->remove($defaultHeader);
}
}
}
from saloon.
Related Issues (20)
- Rate Limit Plugin: Issue with 'allow(1)->everySeconds(1)->sleep()' Exceeding One Request per Second
- Inteliphense cannot recognize the merge() method on request HOT 3
- Connector default headers overwrite request body headers
- Remove authentication on a specific request HOT 5
- Some properties are removed from the response body
- Using non-standard HTTP methods HOT 2
- Generating Documentation Files for GPT on ChatGPT HOT 4
- Tests using Fixtures with custom Authenticators record incorrect response HOT 1
- async request with multi connector HOT 1
- Allow partial overriding of fixtures HOT 2
- Asserting a request is sent by closure parameter HOT 1
- Connector object() throws an exception but json returns null|object? HOT 1
- Feature Request: Requests have the ability to return a Colleciton HOT 1
- Connector does not support `defaultBody()`? HOT 3
- Request class cannot accept `$query` property in constructor HOT 3
- Possible to Use Multiple Instances of Same Request in Single Test?
- Offloading a Listener for SentSaloonRequest events to a queue returns error HOT 3
- Pagination: `currentPage` doesn't align with `page` HOT 2
- Additional requests with the main request
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from saloon.