Skip to content

Commit 50c74a4

Browse files
committed
Merge pull request mozilla#1663 from asraniel/authentication
HTTP Header support
2 parents 5283289 + e1146b6 commit 50c74a4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/api.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
* e.g. No cross domain requests without CORS.
99
*
1010
* @param {string|TypedAray} source Either a url to a PDF is located or a
11-
* typed array already populated with data.
11+
* typed array (Uint8Array) already populated with data.
12+
* @param {Object} headers An object containing the http headers like this:
13+
* { Authorization: "BASIC XXX" }.
1214
* @return {Promise} A promise that is resolved with {PDFDocumentProxy} object.
1315
*/
14-
PDFJS.getDocument = function getDocument(source) {
16+
PDFJS.getDocument = function getDocument(source, headers) {
1517
var promise = new PDFJS.Promise();
1618
var transport = new WorkerTransport(promise);
1719
if (typeof source === 'string') {
@@ -29,7 +31,8 @@ PDFJS.getDocument = function getDocument(source) {
2931
error: function getPDFError(e) {
3032
promise.reject('Unexpected server response of ' +
3133
e.target.status + '.');
32-
}
34+
},
35+
headers: headers
3336
},
3437
function getPDFLoad(data) {
3538
transport.sendData(data);

src/core.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ function getPdf(arg, callback) {
3131
params = { url: arg };
3232

3333
var xhr = new XMLHttpRequest();
34+
3435
xhr.open('GET', params.url);
36+
37+
var headers = params.headers;
38+
if (headers) {
39+
for (var property in headers) {
40+
if (typeof headers[property] === 'undefined')
41+
continue;
42+
43+
xhr.setRequestHeader(property, params.headers[property]);
44+
}
45+
}
46+
3547
xhr.mozResponseType = xhr.responseType = 'arraybuffer';
3648
var protocol = params.url.indexOf(':') < 0 ? window.location.protocol :
3749
params.url.substring(0, params.url.indexOf(':') + 1);

0 commit comments

Comments
 (0)