|
1 | 1 | var fetchTextFromURL; |
2 | 2 | if (typeof XMLHttpRequest != 'undefined') { |
3 | | - fetchTextFromURL = function(url, fulfill, reject) { |
| 3 | + fetchTextFromURL = function(url, authorization, fulfill, reject) { |
4 | 4 | var xhr = new XMLHttpRequest(); |
5 | 5 | var sameDomain = true; |
6 | 6 | var doTimeout = false; |
|
40 | 40 | }; |
41 | 41 | xhr.open("GET", url, true); |
42 | 42 |
|
43 | | - if (xhr.setRequestHeader) |
| 43 | + if (xhr.setRequestHeader) { |
44 | 44 | xhr.setRequestHeader('Accept', 'application/x-es-module */*'); |
| 45 | + // can set "authorization: true" to enable withCredentials only |
| 46 | + if (authorization) { |
| 47 | + if (typeof authorization == 'string') |
| 48 | + xhr.setRequestHeader('Authorization', authorization); |
| 49 | + xhr.withCredentials = true; |
| 50 | + } |
| 51 | + } |
45 | 52 |
|
46 | 53 | if (doTimeout) |
47 | 54 | setTimeout(function() { |
|
53 | 60 | } |
54 | 61 | else if (typeof require != 'undefined') { |
55 | 62 | var fs; |
56 | | - fetchTextFromURL = function(url, fulfill, reject) { |
| 63 | + fetchTextFromURL = function(url, authorization, fulfill, reject) { |
57 | 64 | if (url.substr(0, 8) != 'file:///') |
58 | 65 | throw new Error('Unable to fetch "' + url + '". Only file URLs of the form file:/// allowed running in Node.'); |
59 | 66 | fs = fs || require('fs'); |
|
82 | 89 |
|
83 | 90 | SystemLoader.prototype.fetch = function(load) { |
84 | 91 | return new Promise(function(resolve, reject) { |
85 | | - fetchTextFromURL(load.address, resolve, reject); |
| 92 | + fetchTextFromURL(load.address, undefined, resolve, reject); |
86 | 93 | }); |
87 | 94 | }; |
0 commit comments