THRIFT-2821: Add HTTP header support to JavaScript lib
Client: JavaScript lib
Patch: David Sautter
Adds a customHeaders field to the XHR transport options
supporting multiple key-value custom HTTP headers to pass
with the request.
diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js
index c846162..3ea57c8 100644
--- a/lib/js/src/thrift.js
+++ b/lib/js/src/thrift.js
@@ -310,6 +310,7 @@
this.wpos = 0;
this.rpos = 0;
this.useCORS = (options && options.useCORS);
+ this.customHeaders = options ? (options.customHeaders ? options.customHeaders : {}): {};
this.send_buf = '';
this.recv_buf = '';
};
@@ -376,6 +377,11 @@
xreq.open('POST', this.url, !!async);
+ // add custom headers
+ Object.keys(self.customHeaders).forEach(function(prop) {
+ xreq.setRequestHeader(prop, self.customHeaders[prop]);
+ });
+
if (xreq.setRequestHeader) {
xreq.setRequestHeader('Accept', 'application/vnd.apache.thrift.json; charset=utf-8');
xreq.setRequestHeader('Content-Type', 'application/vnd.apache.thrift.json; charset=utf-8');