couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [2/3] fauxton commit: updated refs/heads/master to f772160
Date Mon, 10 Aug 2015 11:12:01 GMT
csrf: refactor code

do not monkey patch the global $.ajax, use a beforeSend hook
instead

PR: #494
PR-URL: https://github.com/apache/couchdb-fauxton/pull/494
Reviewed-By: Robert Newson <rnewson@apache.org>
Reviewed-By: Garren Smith <garren.smith@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/e66fca7e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/e66fca7e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/e66fca7e

Branch: refs/heads/master
Commit: e66fca7ec57ac98b38228ee4157805ec573597cd
Parents: 4f0e092
Author: Robert Kowalski <rok@kowalski.gd>
Authored: Fri Aug 7 23:15:48 2015 +0200
Committer: Robert Kowalski <robertkowalski@apache.org>
Committed: Mon Aug 10 13:11:36 2015 +0200

----------------------------------------------------------------------
 app/app.js | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e66fca7e/app/app.js
----------------------------------------------------------------------
diff --git a/app/app.js b/app/app.js
index 0679683..b48f088 100644
--- a/app/app.js
+++ b/app/app.js
@@ -63,32 +63,25 @@ function (app, $, _, Backbone, Bootstrap, Helpers, Utils, FauxtonAPI,
Couchdb) {
   // Localize or create a new JavaScript Template object
   var JST = window.JST = window.JST || {};
 
-  var parseCookies = function (cookies) {
-    if (!cookies) {
-      return {};
-    }
-    return _.reduce(cookies.split(';'), function (list, cookie) {
-      var parts = cookie.split('=');
-      list[parts.shift().trim()] = decodeURI(parts.join('='));
-      return list;
-    }, {});
-  };
+  $(document).on('ajaxSend', function (elm, xhr, s) {
+
+    function parseCookies (cookies) {
+      if (!cookies) {
+        return {};
+      }
 
-  $._ajax = $.ajax;
+      return _.reduce(cookies.split(';'), function (list, cookie) {
+        var parts = cookie.split('=');
+        list[parts.shift().trim()] = decodeURI(parts.join('='));
+        return list;
+      }, {});
+    }
 
-  $.ajax = function (settings) {
     var cookies = parseCookies(document.cookie);
     var csrf = cookies['CouchDB-CSRF'] ? cookies['CouchDB-CSRF'] : 'true';
-    var origBeforeSend = settings.beforeSend;
-    var newBeforeSend = function (xhr, o) {
-      if (origBeforeSend) {
-        origBeforeSend(xhr, o);
-      }
-      xhr.setRequestHeader('X-CouchDB-CSRF', csrf);
-    };
-    settings.beforeSend = newBeforeSend;
-    return $._ajax(settings);
-  };
+
+    xhr.setRequestHeader('X-CouchDB-CSRF', csrf);
+  });
 
   // Configure LayoutManager with Backbone Boilerplate defaults
   FauxtonAPI.Layout.configure({


Mime
View raw message