Make authentication work

This commit is contained in:
beat 2012-05-07 09:17:00 +02:00
parent 315071ca28
commit 7786e4fefb
2 changed files with 9 additions and 4 deletions

View File

@ -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) {

View File

@ -32,11 +32,14 @@ function getPdf(arg, callback) {
var xhr = new XMLHttpRequest();
if(params.headers){
//TODO: Code this, use xhr.setRequestHeader(key, value);
}
xhr.open('GET', params.url);
if(params.headers){
for(var property in params.headers){
if(typeof(params.headers[property]) !== undefined){
xhr.setRequestHeader(property, params.headers[property]);
}
}
}
xhr.mozResponseType = xhr.responseType = 'arraybuffer';
var protocol = params.url.indexOf(':') < 0 ? window.location.protocol :
params.url.substring(0, params.url.indexOf(':') + 1);