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

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

Open
2 of 3 tasks
bosh-code opened this issue Apr 26, 2024 · 1 comment
Open
2 of 3 tasks

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

bosh-code opened this issue Apr 26, 2024 · 1 comment
Labels

Comments

@bosh-code
Copy link
Contributor

Description

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

Platforms

  • iOS
  • Android
  • Web

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

@unre4l
Copy link

unre4l commented Jun 12, 2024

Im also looking for a way to add a consistent Origin header in requests on android (not tested on ios yet) made from the foreground as well as the background threads.
As far as I have observed, capacitor adds the server.hostname of the config as Origin, but only in get requests made by the foreground thread. For example, a post request delegated to the thread pool will not have an Origin header set at all (and unfortunately it will not pick the one defined in the fetch request options).

Have you experienced this and found a workaround for the origin header?

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

No branches or pull requests

2 participants