Giter Site home page Giter Site logo

Comments (5)

jlevers avatar jlevers commented on July 20, 2024 1

Ah perfect, that worked! Thanks so much, appreciate it.

from saloon.

Sammyjo20 avatar Sammyjo20 commented on July 20, 2024

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.

juse-less avatar juse-less commented on July 20, 2024

@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.

jlevers avatar jlevers commented on July 20, 2024

@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.

juse-less avatar juse-less commented on July 20, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.