Ignore falsy header values and improve ajaxHeaders documentation

This commit is contained in:
Sean Nichols 2016-12-19 00:39:32 -05:00 committed by Sean Nichols
parent 15fe35a589
commit 6fdf81f266
5 changed files with 10 additions and 4 deletions

View File

@ -2189,7 +2189,10 @@ function OpenSeadragon( options ){
if (headers) {
Object.keys(headers).forEach(function (headerName) {
request.setRequestHeader(headerName, headers[headerName]);
// Falsy header values will be ignored
if (headers[headerName]) {
request.setRequestHeader(headerName, headers[headerName]);
}
});
}

View File

@ -81,7 +81,6 @@
* Defaults to the setting in {@link OpenSeadragon.Options}.
* @param {Object} [options.ajaxHeaders={}]
* A set of headers to include when making tile AJAX requests.
* Note that these headers will be merged over any headers specified in {@link OpenSeadragon.Options}.
*/
$.TiledImage = function( options ) {
var _this = this;

View File

@ -582,6 +582,9 @@ $.TileSource.prototype = {
* Responsible for retrieving the headers which will be attached to the image request for the
* region specified by the given x, y, and level components.
* This option is only relevant if {@link OpenSeadragon.Options}.loadTilesWithAjax is set to true.
* The headers returned here will override headers specified at the Viewer or TiledImage level.
* Specifying a falsy value for a header will clear its existing value set at the Viewer or
* TiledImage level (if any).
* @function
* @param {Number} level
* @param {Number} x

View File

@ -1239,6 +1239,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
* @param {Object} [options.ajaxHeaders]
* A set of headers to include when making tile AJAX requests.
* Note that these headers will be merged over any headers specified in {@link OpenSeadragon.Options}.
* Specifying a falsy value for a header will clear its existing value set at the Viewer level (if any).
* requests.
* @param {Function} [options.success] A function that gets called when the image is
* successfully added. It's passed the event object which contains a single property:

View File

@ -58,14 +58,14 @@
ajaxHeaders: {
// Example of using the viewer-level ajaxHeaders option
// for providing an authentication token.
'Authentication': 'Bearer MY_AUTH_TOKEN'
"Authentication": "Bearer MY_AUTH_TOKEN"
}
});
viewer.addTiledImage({
// The headers specified here will be combined with those in the Viewer object (if any)
ajaxHeaders: {
"X-My-TileSource-Header": "Something"
"X-My-TiledImage-Header": "Something"
},
tileSource: myCustomTileSource
});