fix(ios): remove new line character in multipart/form-data requests
Removes new line characters \r\n which are incorrectly appended to the data of multipart/form-data requests. This change removes these new line characters in order to comply with the specifications, as defined here: https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
Fixes: ionic-team/capacitor#6748
Note, these changes were originally suggested by @hyrex here: https://github.com/heyrex/capacitor-heyrex/pull/1 and in the related issue that is linked to this pull request.
Since this problem is a big deal for developers and buried deep in iOS logic this should be addressed as soon as possible which is why I want to put more attention on this.
Can you provide a sample app that reproduces the issue?
@jcesarmobile sure it's super easy to reproduce, see the example app here: https://github.com/michaelwolz/multipart-form-data-not-working-on-ios (note that CapacitorHttp is activated via capacitor.config.json).
Relevant code can be seen here: https://github.com/michaelwolz/multipart-form-data-not-working-on-ios/blob/47dcecd4395ecf9873dbc90f54a54bfadfd3dd74/src/js/capacitor-welcome.js#L78-L91
See the raw request body and the empty lines before the separator. I think a lot of servers still handle this well but it's definitely not correct according to the specifications.
Also, see the same request from Chrome Browser: