11var Promise = require ( 'bluebird' ) ;
22var _ = require ( 'lodash' ) ;
3- var normalizeUrl = require ( 'normalize-url' ) ;
43
54var logger = require ( './logger' ) ;
65
@@ -12,6 +11,7 @@ var getFilenameGenerator = require('./filename-generators');
1211var makeRequest = require ( './request' ) ;
1312var getResourceHandler = require ( './file-handlers' ) ;
1413var FSAdapter = require ( './fs-adaper' ) ;
14+ var utils = require ( './utils' ) ;
1515
1616function Scraper ( options ) {
1717 var self = this ;
@@ -52,23 +52,19 @@ Scraper.prototype.getOccupiedFileNames = function getOccupiedFileNames () {
5252} ;
5353
5454Scraper . prototype . addRespondedResourcePromise = function addRespondedResourcePromise ( url , promise ) {
55- url = normalizeUrl ( url ) ;
56- this . respondedResourcePromises [ url ] = promise ;
55+ this . respondedResourcePromises [ utils . normalizeUrl ( url ) ] = promise ;
5756} ;
5857
5958Scraper . prototype . getRespondedResourcePromise = function getRespondedResourcePromise ( url ) {
60- url = normalizeUrl ( url ) ;
61- return this . respondedResourcePromises [ url ] ;
59+ return this . respondedResourcePromises [ utils . normalizeUrl ( url ) ] ;
6260} ;
6361
6462Scraper . prototype . addLoadedResourcePromise = function addLoadedResourcePromise ( url , promise ) {
65- url = normalizeUrl ( url ) ;
66- this . loadedResourcePromises [ url ] = promise ;
63+ this . loadedResourcePromises [ utils . normalizeUrl ( url ) ] = promise ;
6764} ;
6865
6966Scraper . prototype . getLoadedResourcePromise = function getLoadedResourcePromise ( url ) {
70- url = normalizeUrl ( url ) ;
71- return this . loadedResourcePromises [ url ] ;
67+ return this . loadedResourcePromises [ utils . normalizeUrl ( url ) ] ;
7268} ;
7369
7470Scraper . prototype . getHtmlSources = function getHtmlSources ( ) {
@@ -123,7 +119,7 @@ Scraper.prototype.requestResource = function requestResource (resource) {
123119 } ) . then ( function requestCompleted ( responseData ) {
124120 logger . debug ( 'received response for ' + url ) ;
125121
126- if ( responseData . url !== url ) { // Url may be changed in redirects
122+ if ( ! utils . urlsEqual ( responseData . url , url ) ) { // Url may be changed in redirects
127123 logger . debug ( 'url changed. old url = ' + url + ', new ulr = ' + responseData . url ) ;
128124 resource . setUrl ( responseData . url ) ;
129125 self . addRespondedResourcePromise ( responseData . url , respondedResourcePromise ) ;
0 commit comments