ionic-team / ionic-team/capacitor

[Feature]: Allow setting global headers for Capacitor Http

Open
#7,432 2 comments 4 reactions 0 assignees View on GitHub
triage
Dominant language
TypeScript
Stars
16.7k
Forks
1.3k
Avg merge
3d 15h
Merged PRs (30d)
10

Description

### Description

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

### Platforms

- [X] iOS
- [X] 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:

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

Then in native-bridge:
```js
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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.