Capacitor HTTP Plugin Not Sending Header on iOS

I’m attempting to use the Capacitor HTTP plugin to make an API call to a hosted service that requires an Authorization HTTP header with each request. This works when running in the browser (and when the HTTP plugin is replaced with plain fetch()) but does not succeed when running on iOS.

The code is pretty straightforward:

const response = await CapacitorHttp.get({
    url: url.toString(),
    headers: {
        'Authorization': `Token ${settings.token}`
    }
});

When running on an iOS device (or simulator), I can attach the Safari dev tools and see the request being sent to the native plugin from the console and verify that the URL and headers are correct:

But the response data back from the server is very clear: “Authentication credentials were not provided”. It’s simply not getting that header. I have tried making the same request in a REST client and that message only shows when the header is missing (as in there’s a different error when the token is invalid).

Am I setting the header wrong? How it is supposed to be set?

Just commenting to say i’m also experiencing this problem right now.

1 Like

I believe this is related to how CapacitorHttp uses Swift’s URLRequest. Apparently some headers are considered “reserved” per Apple’s documentation. I’ve opened a bug in the Capacitor repo here.

Another update: this is not a bug, but a bad response from the API I’m trying to interact with.