Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m.request should support more data for the request body #2812

Open
pygy opened this issue Jan 17, 2023 · 2 comments
Open

m.request should support more data for the request body #2812

pygy opened this issue Jan 17, 2023 · 2 comments
Assignees
Labels
minor Type: Bug For bugs and any other unexpected breakage Type: Enhancement For any feature request or suggestion that isn't a bug fix

Comments

@pygy
Copy link
Member

pygy commented Jan 17, 2023

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:

if (body == null) xhr.send()
else if (typeof args.serialize === "function") xhr.send(args.serialize(body))
else if (body instanceof $window.FormData || body instanceof $window.URLSearchParams) xhr.send(body)
else xhr.send(JSON.stringify(body))

Mithril.js version:
All versions up to 2.2.2

@pygy pygy added Type: Bug For bugs and any other unexpected breakage Type: Enhancement For any feature request or suggestion that isn't a bug fix minor labels Jan 17, 2023
@plybrd
Copy link

plybrd commented Jan 28, 2023

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

@pygy
Copy link
Member Author

pygy commented Jan 28, 2023

@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:

function FormData() {}
var $window = {
FormData: FormData,

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Type: Bug For bugs and any other unexpected breakage Type: Enhancement For any feature request or suggestion that isn't a bug fix
Projects
None yet
Development

No branches or pull requests

3 participants