From 7786e4fefbc4bc2f5f8301b8aaa89c8180ff8999 Mon Sep 17 00:00:00 2001 From: beat Date: Mon, 7 May 2012 09:17:00 +0200 Subject: [PATCH] Make authentication work --- src/api.js | 2 ++ src/core.js | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/api.js b/src/api.js index b3415c0..0c48658 100644 --- a/src/api.js +++ b/src/api.js @@ -9,6 +9,8 @@ * * @param {string|TypedAray} source Either a url to a PDF is located or a * typed array (Uint8Array) already populated with data. + * @param {Object} headers An object containing the http headers like this: + * { Authorization: "BASIC XXX" } * @return {Promise} A promise that is resolved with {PDFDocumentProxy} object. */ PDFJS.getDocument = function getDocument(source, headers) { diff --git a/src/core.js b/src/core.js index 908ba63..e999550 100644 --- a/src/core.js +++ b/src/core.js @@ -32,11 +32,14 @@ function getPdf(arg, callback) { var xhr = new XMLHttpRequest(); + xhr.open('GET', params.url); if(params.headers){ - //TODO: Code this, use xhr.setRequestHeader(key, value); + for(var property in params.headers){ + if(typeof(params.headers[property]) !== undefined){ + xhr.setRequestHeader(property, params.headers[property]); + } + } } - - xhr.open('GET', params.url); xhr.mozResponseType = xhr.responseType = 'arraybuffer'; var protocol = params.url.indexOf(':') < 0 ? window.location.protocol : params.url.substring(0, params.url.indexOf(':') + 1); -- 2.39.5