Closed nip3o closed 1 year ago
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.
Bug Report
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 4.6.1 @capacitor/core: 4.6.1 @capacitor/android: 4.6.1 @capacitor/ios: 4.6.1
Installed Dependencies:
@capacitor/android: not installed @capacitor/cli: 4.6.1 @capacitor/ios: 4.6.1 @capacitor/core: 4.6.1
[success] iOS looking great! 👌
Platform(s)
Only iOS
Current Behavior
Giving the value of a HTTP header as a number rather than as string causes the exception
Could not cast value of type '__NSCFNumber' (0x122864c30) to 'NSString' (0x1b7cc7fc8).
to be thrown when the value is unpacked in HttpRequestHandler.Expected Behavior
The numeric value should be converted to a string. This is what the Android version of the plugin does, and what the Safari browser implementation of
fetch()
does. One could definitely argue that header values should always be passed in as strings, but I don't think it's helpful to crash on it. Either way, plugin code should not crash internally due to user errors.Code Reproduction
https://github.com/nip3o/capacitor-http-headers-crash
Other Technical Details
npm --version
output: 6.14.17node --version
output: v14.20.0pod --version
output (iOS issues only): 1.11.3Additional Context
I did not get a stacktrace, but the crash happens in ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift:148:
let headers = (call.getObject("headers") ?? [:]) as! [String: String]
Could not cast value of type '__NSCFNumber' (0x122864c30) to 'NSString' (0x1b7cc7fc8).