From dbaea1afe7afa78b637505de0a4877cbd4e36341 Mon Sep 17 00:00:00 2001 From: nithinkdb Date: Mon, 22 Aug 2022 13:49:55 -0700 Subject: [PATCH 1/2] Added conditional support in xhr --- lib/nodejs/lib/thrift/xhr_connection.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/nodejs/lib/thrift/xhr_connection.js b/lib/nodejs/lib/thrift/xhr_connection.js index 6459c900c2a..5ff733e107b 100644 --- a/lib/nodejs/lib/thrift/xhr_connection.js +++ b/lib/nodejs/lib/thrift/xhr_connection.js @@ -22,6 +22,7 @@ var thrift = require('./thrift'); var TBufferedTransport = require('./buffered_transport'); var TJSONProtocol = require('./json_protocol'); +var TBinaryProtocol = require('./binary_protocol'); var InputBufferUnderrunError = require('./input_buffer_underrun_error'); var createClient = require('./create_client'); @@ -102,13 +103,22 @@ XHRConnection.prototype.flush = function() { var xreq = this.getXmlHttpRequestObject(); + if (this.protocol == TBinaryProtocol) { + xreq.responseType = 'arraybuffer'; + } + if (xreq.overrideMimeType) { xreq.overrideMimeType('application/json'); } xreq.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { - self.setRecvBuffer(this.responseText); + if(this.protocol == TBinaryProtocol) { + self.setRecvBuffer(this.response); + } + else { + self.setRecvBuffer(this.responseText); + } } }; From f05720c1faf9b2ecf0a1d14ab4a547ff3a393223 Mon Sep 17 00:00:00 2001 From: nithinkdb Date: Mon, 22 Aug 2022 16:34:32 -0700 Subject: [PATCH 2/2] Changed this to self, for state check --- lib/nodejs/lib/thrift/xhr_connection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nodejs/lib/thrift/xhr_connection.js b/lib/nodejs/lib/thrift/xhr_connection.js index 5ff733e107b..746b8f11909 100644 --- a/lib/nodejs/lib/thrift/xhr_connection.js +++ b/lib/nodejs/lib/thrift/xhr_connection.js @@ -113,7 +113,7 @@ XHRConnection.prototype.flush = function() { xreq.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { - if(this.protocol == TBinaryProtocol) { + if(self.protocol == TBinaryProtocol) { self.setRecvBuffer(this.response); } else {