ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.24k stars 955 forks source link

[Feature]: Allow setting global headers for Capacitor Http #7432

Open bosh-code opened 3 weeks ago

bosh-code commented 3 weeks ago

Description

Add a section in the capactitor config for headers to be used by the capacitor Http plugin, similar to User Agent config.

Platforms

Request or proposed solution

I'm happy to do the changes for it if it something the maintainers would like to implement. I'm suggesting it as we have had to do it at work so requests to one of our APIs work.

In the capacitor configuration, something like this:

...
 plugins: {
    CapacitorHttp: {
      enabled: true,
      customHeaders: {
        Origin: 'example.com'
        ...
    },
...

Then in native-bridge:

convertBody(body).then(({ data, type, headers }) => {
  // Example based on the patch I wrote for our app:
  otherheaders = {
    ...customHeaders, // From cap config
    ...otherHeaders
  }
  ...

Alternatives

No response

Additional Information

No response