gopherjs / gopherjs.github.io

GopherJS Playground
https://gopherjs.github.io/playground/
23 stars 12 forks source link

playground: Send data unmodified via XHR binary mode. #22

Closed dmitshur closed 9 years ago

dmitshur commented 9 years ago

We don't want the raw bytes to change from client to server, so send using binary mode. This is done by using []byte parameter, which gets externalized into Uint8Array aka ArrayBufferView, which is one of the parameters that XHR send accepts for sending binary data.

This is based on my newfound understanding of ArrayBufferView from discussion at https://github.com/gopherjs/gopherjs/commit/59323cd88acd2923912b367ed99deddfeeb44f66#commitcomment-9452804. @neelance, I'd like for you to confirm my understanding is correct before merging this.

If everything checks out, the XHR package docs should be updated to include that []byte is a valid input type for binary transfer.

Finally, the .go file needs to be built and likely the entire playground updated via update.sh since there've been changes to GopherJS compiler.

Tasks before merging

dmitshur commented 9 years ago

Task 1 is done in https://github.com/gopherjs/gopherjs/issues/167.

Creating issue for task 2, made https://github.com/dominikh/go-js-xhr/issues/4.

dmitshur commented 9 years ago

All 3 tasks done, this PR is ready to be merged.

dmitshur commented 9 years ago

On second thought, there are improvements to xhr package forthcoming in https://github.com/dominikh/go-js-xhr/pull/6, so let's hold off from merging this PR until then. The upstream API improvements will supersede the current change in this PR, allowing a further simplification of code.

dmitshur commented 9 years ago

Okay, I will merge this as is now because this PR fixes a production issue/task. Code refactoring can be done separately in a followup PR, as it's still ongoing research as to what the best library/API to use.