-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dlasky
committed
Sep 10, 2015
1 parent
0535ca8
commit 348c1ed
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<link rel="import" href="datautils.html"/> | ||
<script> | ||
(function(scope) { | ||
scope.AjaxBusterPlugin = function AjaxBusterPlugin(enabled, name) { | ||
this.enabled = enabled; | ||
this.name = name || "nocache"; | ||
} | ||
AjaxBuster.prototype = { | ||
requestHandler: function(ajaxOptions) { | ||
if (this.enabled) { | ||
ajaxOptions.queryParams.push(DataUtils.param(this.name, Date.now())); | ||
} | ||
} | ||
responseHandler: function(response) { | ||
return response; | ||
} | ||
reset: function() { | ||
|
||
} | ||
}; | ||
}(window.StrandLib = window.StrandLib || {})); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<link rel="import" href="ajaxplugin.html"/> | ||
<link rel="import" href="storage.html"/> | ||
<link rel="import" href="datautils.html"/> | ||
<script> | ||
(function(scope) { | ||
var DataUtils = StrandLib.DataUtils; | ||
var Storage = StrandLib.Storage; | ||
|
||
scope.AjaxCSRFPlugin = function AjaxCSRFPlugin(enable, useCache, header) { | ||
this.enabled = enable; | ||
this.useCache = useCache; | ||
this.header = header || "X-CSRF-Token"; | ||
if (this.useCache) { | ||
this.storage = new Storage("csrf"); | ||
this.token = this.storage.value; | ||
} | ||
} | ||
|
||
AjaxCSRFPlugin.prototype = { | ||
|
||
requestHandler:function(ajaxOpts) { | ||
if (this.enabled && ajaxOpts && this.token) { | ||
var csrf = DataUtils.param(this.csrfHeader, this.token); | ||
ajaxOpts.headers.push(csrf); | ||
} | ||
return ajaxOpts; | ||
}, | ||
|
||
responseHandler:function(response) { | ||
var ajax = DataUtils.getPathValue("instance",response); | ||
var hasHeader = ajax.xhr.getAllResponseHeaders().indexOf(this.csrfHeader) !== -1; | ||
if (hasHeader && this.enabled) { | ||
var csrf = ajax.xhr.getResponseHeader(this.csrfHeader); | ||
this.token = csrf; | ||
if (this.useCache) { | ||
this.storage.value = csrf; | ||
} | ||
} | ||
return response; | ||
}, | ||
reset:function() { | ||
|
||
} | ||
}; | ||
}(window.StrandLib = window.StrandLib || {})); | ||
|
||
</script> |