Skip to content

Commit f033e2e

Browse files
committed
playground: Send data unmodified via XHR binary mode.
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. See dominikh/go-js-xhr#4 for details.
1 parent 96b7a8f commit f033e2e

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

playground/playground.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ func main() {
221221
req := xhr.NewRequest("POST", "http://"+snippetStoreHost+"/share")
222222
req.ResponseType = xhr.ArrayBuffer
223223
go func() {
224-
// TODO: Send as binary?
225-
err := req.Send(scope.Get("code").String())
224+
err := req.Send([]byte(scope.Get("code").String())) // Send as binary.
226225
if err != nil || req.Status != 200 {
227226
scope.Apply(func() {
228227
scope.Set("output", []Line{Line{"type": "err", "content": `failed to share snippet`}})

playground/playground.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65171,7 +65171,7 @@ $packages["github.com/gopherjs/gopherjs.github.io/playground"] = (function() {
6517165171
$go((function($b) {
6517265172
var $args = arguments, $r, $s = 0, $this = this, _r, data, err;
6517365173
/* */ if($b !== $BLOCKING) { $nonblockingCall(); }; var $f = function() { s: while (true) { switch ($s) { case 0:
65174-
_r = req$1.Send(new $String($internalize(scope.Object.code, $String)), $BLOCKING); /* */ $s = 1; case 1: if (_r && _r.$blocking) { _r = _r(); }
65174+
_r = req$1.Send(new sliceType$2($stringToBytes($internalize(scope.Object.code, $String))), $BLOCKING); /* */ $s = 1; case 1: if (_r && _r.$blocking) { _r = _r(); }
6517565175
err = _r;
6517665176
if (!($interfaceIsEqual(err, $ifaceNil)) || !((($parseInt(req$1.Object.status) >> 0) === 200))) {
6517765177
scope.Apply((function() {

0 commit comments

Comments
 (0)