Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

cannot overwrite default request headers on ios #261

Open
katonap opened this issue May 31, 2022 · 0 comments
Open

cannot overwrite default request headers on ios #261

katonap opened this issue May 31, 2022 · 0 comments

Comments

@katonap
Copy link

katonap commented May 31, 2022

We use capacitor and this http plugin in an angular application. The Accept-Language header is set on the request (Http.request()), but when it is sent to the server we see additional languages in this header, not just the one we set.

I found that CapacitorUrlRequest initializes the Accept-Language header based on some device settings. Later when setRequestHeaders() is called it appends the parameter headers to the existing ones, not overwrites them. This means that the parameter language for the Accept-Language header will be the last language in the header, and because the first one has a quality value of 1 (as the default), our language can never have a higher priority than that.
I beleive calling request.setValue() instead of the current request.addValue() would solve this problem. URLRequest docs

As an additional info the java code for android overwrites the headers in CapacitorHttpUrlConnection.setRequestHeaders().

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant