]> git.parisson.com Git - pdf.js.git/commitdiff
Make authentication work
authorbeat <beat.wolf@hefr.ch>
Mon, 7 May 2012 07:17:00 +0000 (09:17 +0200)
committerbeat <beat.wolf@hefr.ch>
Mon, 7 May 2012 07:17:00 +0000 (09:17 +0200)
src/api.js
src/core.js

index b3415c08efd874d8bddd92442af748d6961f629e..0c48658414965b1f3f46ba09fa2891b948d50247 100644 (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) {
index 908ba63afb493bca7d5625869f85cb3dbee328a3..e999550ca8185f761a3e69f8a51dc03de695ea6e 100644 (file)
@@ -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);