From 6fdf81f26676a712966044a3bc7ced2fcdfc0a8f Mon Sep 17 00:00:00 2001 From: Sean Nichols Date: Mon, 19 Dec 2016 00:39:32 -0500 Subject: [PATCH] Ignore falsy header values and improve ajaxHeaders documentation --- src/openseadragon.js | 5 ++++- src/tiledimage.js | 1 - src/tilesource.js | 3 +++ src/viewer.js | 1 + test/demo/customheaders.html | 4 ++-- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index a5116963..d2c52174 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -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]); + } }); } diff --git a/src/tiledimage.js b/src/tiledimage.js index f9b311cc..16ef99b5 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -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; diff --git a/src/tilesource.js b/src/tilesource.js index 66bb10ac..d8c16803 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -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 diff --git a/src/viewer.js b/src/viewer.js index a5b3104f..a3a09828 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -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: diff --git a/test/demo/customheaders.html b/test/demo/customheaders.html index 4937b231..cdd98401 100644 --- a/test/demo/customheaders.html +++ b/test/demo/customheaders.html @@ -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 });