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

gives overrides options higher priority to the payload #6

Closed
wants to merge 1 commit into from
Closed

gives overrides options higher priority to the payload #6

wants to merge 1 commit into from

Conversation

vboulaye
Copy link

@vboulaye vboulaye commented May 1, 2020

Hello,
I am trying to use sapper-httpclient in a project of mine, but I need to set an Authorization header.

The override() method looks like a nice place to do this, and it works fine for all the GET calls:

create()
 .endpoint('https://myserver.com/')
 .override({
      headers: {
        'Authorization': 'Basic ' + Buffer.from(user.username + ":" + user.password).toString('base64'),
      },
    })
 .get()

But when I set a payload() in a POST or PUT calls, it overrides all the headers with a 'Content-Type': 'application/json' and I have no way to change this.

In order to fix this, I tried switching the payload and overrides during the merge into the request options object.

@antony
Copy link
Member

antony commented May 1, 2020

Well spotted! I don't use headers much myself so I've not run into this.

I think the correct solution to this is proper header support (see commit below), and I've added some tests around the new .headers() method.

Released as 3.6.0

5d1880b

@antony antony closed this May 1, 2020
@vboulaye
Copy link
Author

vboulaye commented May 1, 2020

Yes, it is better with a specific method dedicated to headers (with the override workaround I had to repeat the Accept/Content-type header)
thanks a lot!

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.

None yet

2 participants