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

bug: CapacitorHttp XMLHttpRequest (Angular HttpClient) interceptor doesn't pass headers correctly #6274

Closed
dennisameling opened this issue Feb 5, 2023 · 6 comments

Comments

@dennisameling
Copy link
Contributor

dennisameling commented Feb 5, 2023

Bug Report

Capacitor Version

% npx cap doctor  
💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 4.6.3
  @capacitor/core: 4.6.3
  @capacitor/android: 4.6.3
  @capacitor/ios: 4.6.3

Installed Dependencies:

  @capacitor/cli: 4.6.3
  @capacitor/core: 4.6.3
  @capacitor/android: 4.6.3
  @capacitor/ios: 4.6.3

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

Android and iOS

Current Behavior

When using Angular's HttpClient in combination with Capacitor's CapacitorHttp intercepting enabled, headers are sent incorrectly to the server.

Here's what it looks like on Android (did remote debugging to get some more details):

Screenshot 2023-02-05 at 11 32 27

Note that the headers are a JSON-encoded string when CapacitorHttp is intercepting XMLHttpRequest. That doesn't seem right!

And here's what it looks like on iOS:

IMG_0064

Expected Behavior

I expect Angular's HttpClient to work correctly in combination with CapacitorHttp's XMLHttpRequest interceptor.

Code Reproduction

Here's the full codebase of my screenshots above: https://github.com/dennisameling/capacitor-http-bug

Other Technical Details

npm --version output: 8.19.2

node --version output: v16.18.1

pod --version output (iOS issues only): 1.11.2

Additional Context

@matudelatower
Copy link

Same issue here, apparently overwrites all request even @angular/common/http, and interceptors doesnt work.

@jonesdhtx
Copy link

jonesdhtx commented Feb 9, 2023

Having similar issue using fetch directly from within our capacitor project, request headers are no longer getting sent properly. Seems like this change would be the culprit: https://github.com/ionic-team/capacitor/pull/6251/files

@brandonaaron
Copy link

I'm also pointing the finger at PR #6251 for breaking http calls. App works fine in 4.6.2 but server gets bad/missing info on 4.6.3.

@muuvmuuv
Copy link

Since its Native → Browser it could be due to Access-Control-Expose-Headers. Can you try adding that to your server and select the headers you want to expose to the client?

@davy-ikv
Copy link

This change breaks passing headers in iOS

028c556#diff-73da2144bc5fefb384b6fc1501a8efbabac7cfdf2faa411b68cdd113f53d884dL430-R432

JSON.stringify headers makes headers become a String, but in native part of iOS, it expect headers is a hash table ([String: String])

@jcesarmobile
Copy link
Member

Resolved on #6303

@ionic-team ionic-team locked as resolved and limited conversation to collaborators Feb 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants