mithril.js icon indicating copy to clipboard operation
mithril.js copied to clipboard

`m.request` should support more data for the request body

Open pygy opened this issue 2 years ago • 2 comments

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:

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

pygy avatar Jan 17 '23 08:01 pygy

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 avatar Jan 28 '23 12:01 plybrd

@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

pygy avatar Jan 28 '23 14:01 pygy