You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make it possible to provide FormData transparently #60
in case of a FormData it was best for me to let the request set the proper multipart content type and especially set the 'boundary' correctly so that the parameters arrived properly on the server.
Side note: In my local atomic.js version I added support for 'timeout' settings via options like:
// Add timeout TODO: this was added by AJ (clubcooee) as of 07th of february 2018.
if (settings.timeout) {
request.timeout = settings.timeout;
@cferdinandi Heya! Thanks for the lightweight library!
I think this issue persists—there's no way to un-set the Content-Type header specified in the defaults object (per @ajorias's note), at request-time.
When using FormData as data, the request is missing the boundary piece of the header, which makes the data unreadable, server-side. There may be more relaxed requirements in some server environments, but I found that the browser was at least able to do its auto-magic when this was removed from the dist files.
Would you be willing to revisit? I'm happy to issue a PR with this removed, but I'm weary that it would be breaking for others' uses. 😬
Ordinarily, yeah—but the boundary value is generated by the browser, and as far as I can tell, can't be spoofed/reproduced without completely customizing how the body is “serialized,” which defeats the point 😉
Speaking specifically about the latter half of this:
I think so? I mean, this is probably the means to a backwards-compatible solution. 👍
In fiddling, I tried to unset by passing null, but it actually appended/joined the two settings together, rather than removing it—resulting incontent-type: multipart/form-data, null 🤔
Activity
cferdinandi commentedon May 19, 2018
Absolutely, and this is an easy fix. I'll try to do this this week.
For my own reference on checking for the FormData object type: https://codepen.io/pen/
ajorias commentedon May 19, 2018
Awesome. I added
to the param() function but that's no quit enough because of the default header
in case of a FormData it was best for me to let the request set the proper multipart content type and especially set the 'boundary' correctly so that the parameters arrived properly on the server.
Side note: In my local atomic.js version I added support for 'timeout' settings via options like:
Just before the .send()
cferdinandi commentedon May 19, 2018
I like that too! Great ideas!
cferdinandi commentedon May 20, 2018
I added
FormDatasupport and an option fortimeoutin the just released v4.1.0. Thanks for suggesting these!AugustMiller commentedon Sep 9, 2019
@cferdinandi Heya! Thanks for the lightweight library!
I think this issue persists—there's no way to un-set the
Content-Typeheader specified in thedefaultsobject (per @ajorias's note), at request-time.When using
FormDataasdata, the request is missing theboundarypiece of the header, which makes the data unreadable, server-side. There may be more relaxed requirements in some server environments, but I found that the browser was at least able to do its auto-magic when this was removed from the dist files.Would you be willing to revisit? I'm happy to issue a PR with this removed, but I'm weary that it would be breaking for others' uses. 😬
👋
cferdinandi commentedon Sep 9, 2019
@AugustMiller I'm maybe missing something, but... can't you update the
Content-Typeheader using the public options?AugustMiller commentedon Sep 9, 2019
Ordinarily, yeah—but the
boundaryvalue is generated by the browser, and as far as I can tell, can't be spoofed/reproduced without completely customizing how the body is “serialized,” which defeats the point 😉Speaking specifically about the latter half of this:
…which the browser sets automatically when
XMLHttpRequestis givenFormData, but not when the header has already been explicitly set.Hope this makes sense?
Edit: Thanks for the quick response! 💞
cferdinandi commentedon Sep 9, 2019
Ah, you actually need a way to "unset" items, then?
AugustMiller commentedon Sep 9, 2019
I think so? I mean, this is probably the means to a backwards-compatible solution. 👍
In fiddling, I tried to unset by passing
null, but it actually appended/joined the two settings together, rather than removing it—resulting incontent-type: multipart/form-data, null🤔cferdinandi commentedon Sep 9, 2019
Yea, I'll need to add a new method to support this behavior.