Merge pull request #1663 from asraniel/authentication
HTTP Header support
This commit is contained in:
commit
50c74a4825
@ -8,10 +8,12 @@
|
|||||||
* e.g. No cross domain requests without CORS.
|
* e.g. No cross domain requests without CORS.
|
||||||
*
|
*
|
||||||
* @param {string|TypedAray} source Either a url to a PDF is located or a
|
* @param {string|TypedAray} source Either a url to a PDF is located or a
|
||||||
* typed array already populated with data.
|
* 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.
|
* @return {Promise} A promise that is resolved with {PDFDocumentProxy} object.
|
||||||
*/
|
*/
|
||||||
PDFJS.getDocument = function getDocument(source) {
|
PDFJS.getDocument = function getDocument(source, headers) {
|
||||||
var promise = new PDFJS.Promise();
|
var promise = new PDFJS.Promise();
|
||||||
var transport = new WorkerTransport(promise);
|
var transport = new WorkerTransport(promise);
|
||||||
if (typeof source === 'string') {
|
if (typeof source === 'string') {
|
||||||
@ -29,7 +31,8 @@ PDFJS.getDocument = function getDocument(source) {
|
|||||||
error: function getPDFError(e) {
|
error: function getPDFError(e) {
|
||||||
promise.reject('Unexpected server response of ' +
|
promise.reject('Unexpected server response of ' +
|
||||||
e.target.status + '.');
|
e.target.status + '.');
|
||||||
}
|
},
|
||||||
|
headers: headers
|
||||||
},
|
},
|
||||||
function getPDFLoad(data) {
|
function getPDFLoad(data) {
|
||||||
transport.sendData(data);
|
transport.sendData(data);
|
||||||
|
12
src/core.js
12
src/core.js
@ -31,7 +31,19 @@ function getPdf(arg, callback) {
|
|||||||
params = { url: arg };
|
params = { url: arg };
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
xhr.open('GET', params.url);
|
xhr.open('GET', params.url);
|
||||||
|
|
||||||
|
var headers = params.headers;
|
||||||
|
if (headers) {
|
||||||
|
for (var property in headers) {
|
||||||
|
if (typeof headers[property] === 'undefined')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
xhr.setRequestHeader(property, params.headers[property]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
xhr.mozResponseType = xhr.responseType = 'arraybuffer';
|
xhr.mozResponseType = xhr.responseType = 'arraybuffer';
|
||||||
var protocol = params.url.indexOf(':') < 0 ? window.location.protocol :
|
var protocol = params.url.indexOf(':') < 0 ? window.location.protocol :
|
||||||
params.url.substring(0, params.url.indexOf(':') + 1);
|
params.url.substring(0, params.url.indexOf(':') + 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user