mithril.js
mithril.js copied to clipboard
`m.request` should support more data for the request body
Per https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send
A body of data to be sent in the XHR request. This can be:
- A Document, in which case it is serialized before being sent.
- An XMLHttpRequestBodyInit, which per the Fetch spec can be a Blob, an ArrayBuffer, a TypedArray, a DataView, a FormData, a URLSearchParams, or a string object or value.
- null
We only support a subset of these: https://github.com/MithrilJS/mithril.js/blob/645cf663b220614d107cde0d86e3a104db3529fc/request/request.js#L143-L146
Mithril.js version: All versions up to 2.2.2
Uploading with the PUT method to a webDAV server needs:
|| body instanceof $window.Blob
See TAF a WebDAV client in JavaScript (just 10KB) featuring mithril.js
@plybrd do you feel like creating a PR for this against the v2.x branch? If so, it would be much appreciated.
The implementation is trivial, and as far as testing goes, I wouldn't worry about faking the functionality in detail. Adding stub constructors like we do for FormData in the xhr mocks will be enough:
https://github.com/MithrilJS/mithril.js/blob/e0996bd6f23fe6e469019c9d126bf8d95be15cff/test-utils/xhrMock.js#L14-L16
The common prototype for all typed arrays can be accessed through Object.getPrototypeOf(&window.Int8Array). You can cache that value in reqest/request.js next to the PromiseProxy definition