You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ra...@apache.org on 2016/04/13 15:29:31 UTC

thrift git commit: THRIFT-2821: Add HTTP header support to JavaScript lib Client: JavaScript lib Patch: David Sautter

Repository: thrift
Updated Branches:
  refs/heads/master 0ea6c1d5d -> 3ca89e60d


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.


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/3ca89e60
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/3ca89e60
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/3ca89e60

Branch: refs/heads/master
Commit: 3ca89e60d231f1f466232599b7138536f401845b
Parents: 0ea6c1d
Author: Randy Abernethy <ra...@apache.org>
Authored: Wed Apr 13 06:24:57 2016 -0700
Committer: Randy Abernethy <ra...@apache.org>
Committed: Wed Apr 13 06:24:57 2016 -0700

----------------------------------------------------------------------
 lib/js/src/thrift.js | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/3ca89e60/lib/js/src/thrift.js
----------------------------------------------------------------------
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 @@ Thrift.Transport = Thrift.TXHRTransport = function(url, options) {
     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 @@ Thrift.TXHRTransport.prototype = {
 
         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');