From f033e2eeb14e21ffa8f10070cdefefcc8985b5e4 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Tue, 27 Jan 2015 18:41:08 -0800 Subject: [PATCH] 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. --- playground/playground.go | 3 +-- playground/playground.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/playground/playground.go b/playground/playground.go index 16dd8079..8c281db5 100644 --- a/playground/playground.go +++ b/playground/playground.go @@ -221,8 +221,7 @@ func main() { req := xhr.NewRequest("POST", "http://"+snippetStoreHost+"/share") req.ResponseType = xhr.ArrayBuffer go func() { - // TODO: Send as binary? - err := req.Send(scope.Get("code").String()) + err := req.Send([]byte(scope.Get("code").String())) // Send as binary. if err != nil || req.Status != 200 { scope.Apply(func() { scope.Set("output", []Line{Line{"type": "err", "content": `failed to share snippet`}}) diff --git a/playground/playground.js b/playground/playground.js index 33f7722b..5ca2e63f 100644 --- a/playground/playground.js +++ b/playground/playground.js @@ -65171,7 +65171,7 @@ $packages["github.com/gopherjs/gopherjs.github.io/playground"] = (function() { $go((function($b) { var $args = arguments, $r, $s = 0, $this = this, _r, data, err; /* */ if($b !== $BLOCKING) { $nonblockingCall(); }; var $f = function() { s: while (true) { switch ($s) { case 0: - _r = req$1.Send(new $String($internalize(scope.Object.code, $String)), $BLOCKING); /* */ $s = 1; case 1: if (_r && _r.$blocking) { _r = _r(); } + _r = req$1.Send(new sliceType$2($stringToBytes($internalize(scope.Object.code, $String))), $BLOCKING); /* */ $s = 1; case 1: if (_r && _r.$blocking) { _r = _r(); } err = _r; if (!($interfaceIsEqual(err, $ifaceNil)) || !((($parseInt(req$1.Object.status) >> 0) === 200))) { scope.Apply((function() {