@@ -29,6 +29,18 @@ var Loader = function (data) {
2929 } ) ;
3030 logger = new Logger ( options . log ) ;
3131
32+ function makeRequest ( url ) {
33+ return request . getAsync ( {
34+ url : url ,
35+ method : 'GET' ,
36+ encoding : encoding ,
37+ strictSSL : false
38+ } )
39+ . then ( function ( response ) {
40+ return response [ 1 ]
41+ } ) ;
42+ }
43+
3244 /**
3345 * Returns local absolute filename associated with url
3446 * @param url - remote url
@@ -116,12 +128,9 @@ var Loader = function (data) {
116128 * @return {Promise }
117129 */
118130 function loadBinaryFileFromUrl ( binaryUrl , filePath ) {
119- return request . getAsync ( {
120- url : binaryUrl ,
121- encoding : 'binary'
122- } )
123- . then ( function ( response ) {
124- return fs . outputFileAsync ( filePath , response [ 1 ] , 'binary' )
131+ return makeRequest ( binaryUrl )
132+ . then ( function ( response ) {
133+ return fs . outputFileAsync ( filePath , response , { encoding : encoding } )
125134 } )
126135 . then ( function ( ) {
127136 logger . log ( binaryUrl + ' -> ' + filePath ) ;
@@ -135,13 +144,9 @@ var Loader = function (data) {
135144 * @return {Promise }
136145 */
137146 function loadCssFileFromUrl ( absoluteUrl , localFilePath ) {
138- return request . getAsync ( {
139- url : absoluteUrl ,
140- method : 'GET' ,
141- encoding : null
142- } )
147+ return makeRequest ( absoluteUrl )
143148 . then ( function ( response ) {
144- return loadCssSources ( response [ 1 ] . toString ( encoding ) , absoluteUrl , localFilePath )
149+ return loadCssSources ( response , absoluteUrl , localFilePath )
145150 } )
146151 . then ( function ( response ) {
147152 return fs . outputFileAsync ( localFilePath , response , { encoding : encoding } )
@@ -279,15 +284,7 @@ var Loader = function (data) {
279284 }
280285
281286 function loadIndexHtml ( ) {
282- return request . getAsync ( {
283- url : options . url ,
284- method : 'GET' ,
285- encoding : null
286- } )
287- . then ( function ( response ) { // Get index page
288- var buffer = response [ 1 ] ;
289- return buffer . toString ( encoding )
290- } )
287+ return makeRequest ( options . url )
291288 . then ( function ( html ) { // Prepare for further loading
292289 return prepare ( html )
293290 } )
0 commit comments