faux-jax icon indicating copy to clipboard operation
faux-jax copied to clipboard

Support responseType = 'arraybuffer'

Open danvk opened this issue 9 years ago • 6 comments

When you set xhr.responseType = 'arraybuffer', xhr.response should be an ArrayBuffer, not a string. It looks like faux-jax does not emulate this behavior (xhr.response remains a string when I set the responseType property).

danvk avatar Feb 18 '15 21:02 danvk

can you do a PR for this? would be awesome. the readme explains how to launch the dev env (npm run dev)

then follow the spec, should not be that hard at all!

vvo avatar Feb 19 '15 07:02 vvo

Ditto for responseType = 'blob'. Should setResponseBody allow a compatible non-string argument if in one of the other modes?

terinjokes avatar Mar 09 '15 18:03 terinjokes

Should setResponseBody allow a compatible non-string argument if in one of the other modes?

Can you detail this? Do not understand what you mean.

vvo avatar Mar 09 '15 20:03 vvo

Can you detail this? Do not understand what you mean.

If the responseType is set to something other than "text" or "", it would be nice if we could set the response body to an instance of that type directly. Otherwise if I want to respond with a Blob, I have to convert and set the response body to a binary string just for faux-ajax to convert it back to a Blob.

terinjokes avatar Mar 09 '15 21:03 terinjokes

I have to convert and set the response body to a binary string just for faux-ajax to convert it back to a Blob.

I think we should keep it this way and let the user do his own helper functions to do this.

The thing is that we must be as close as possible to the way browser will receive a response.

On the network there's no ArrayBuffer or JSON objects, only "strings".

It will also require more work for faux-jax than just passing references: we will have to convert various instances to string and then parse them again at the end.

In progress events, you must be able to access the current responseText, so that for instance you can do streaming JSON parsing from an XHR (well as faux-jax is nearly synchronous I guess, that's not feasible right now).

In the end someone will have to stringify instances and parse them back. So that we also clone objects.

What do you think?

vvo avatar Mar 09 '15 21:03 vvo

Also that's a separate issue :)

vvo avatar Mar 09 '15 21:03 vvo