@@ -82,27 +82,17 @@ def follow_redirect_chain(self, url):
8282 # Make request without following redirects automatically
8383 response = self .session .get (current_url , timeout = self .timeout , allow_redirects = False )
8484
85- # Check if this step leads to home page
86- if self .is_home_page (current_url ):
87- return {
88- 'status_code' : response .status_code ,
89- 'final_url' : current_url ,
90- 'redirect_chain' : redirect_chain ,
91- 'redirect_count' : redirect_count ,
92- 'leads_to_home' : True ,
93- 'home_at_step' : redirect_count ,
94- 'error' : None
95- }
96-
97- # If not a redirect, we're done
85+ # If not a redirect, we're done - check final destination for home page
9886 if response .status_code not in [301 , 302 , 303 , 307 , 308 ]:
87+ # Check if final destination is home page
88+ is_home = self .is_home_page (current_url )
9989 return {
10090 'status_code' : response .status_code ,
10191 'final_url' : current_url ,
10292 'redirect_chain' : redirect_chain ,
10393 'redirect_count' : redirect_count ,
104- 'leads_to_home' : False ,
105- 'home_at_step' : None ,
94+ 'leads_to_home' : is_home ,
95+ 'home_at_step' : redirect_count if is_home else None ,
10696 'error' : None
10797 }
10898
@@ -142,26 +132,41 @@ def follow_redirect_chain(self, url):
142132 'home_at_step' : None ,
143133 'error' : f'Redirect loop detected at step { redirect_count } '
144134 }
135+
136+ # Check if this intermediate redirect step leads to home page
137+ if self .is_home_page (current_url ):
138+ return {
139+ 'status_code' : response .status_code ,
140+ 'final_url' : current_url ,
141+ 'redirect_chain' : redirect_chain ,
142+ 'redirect_count' : redirect_count ,
143+ 'leads_to_home' : True ,
144+ 'home_at_step' : redirect_count ,
145+ 'error' : None
146+ }
145147
146- # Too many redirects
148+ # Too many redirects - check if final URL is home page anyway
149+ is_home = self .is_home_page (current_url )
147150 return {
148151 'status_code' : None ,
149152 'final_url' : current_url ,
150153 'redirect_chain' : redirect_chain ,
151154 'redirect_count' : redirect_count ,
152- 'leads_to_home' : False ,
153- 'home_at_step' : None ,
155+ 'leads_to_home' : is_home ,
156+ 'home_at_step' : redirect_count if is_home else None ,
154157 'error' : f'Too many redirects (>{ self .max_redirects } )'
155158 }
156159
157160 except requests .exceptions .RequestException as e :
161+ # Check if we ended up at home page even with an error
162+ is_home = self .is_home_page (current_url )
158163 return {
159164 'status_code' : None ,
160165 'final_url' : current_url ,
161166 'redirect_chain' : redirect_chain ,
162167 'redirect_count' : redirect_count ,
163- 'leads_to_home' : False ,
164- 'home_at_step' : None ,
168+ 'leads_to_home' : is_home ,
169+ 'home_at_step' : redirect_count if is_home else None ,
165170 'error' : str (e )
166171 }
167172
0 commit comments