@@ -281,18 +281,27 @@ async def _canonicalize_host(loop: asyncio.AbstractEventLoop,
281
281
282
282
host = options .host
283
283
284
- if not options .canonicalize_hostname or not options .canonical_domains or \
285
- host .count ('.' ) > options .canonicalize_max_dots :
284
+ if not options .canonicalize_hostname or not options .canonical_domains :
285
+ logger .info ('Host canonicalization disabled' )
286
+ return None
287
+
288
+ if host .count ('.' ) > options .canonicalize_max_dots :
289
+ logger .info ('Host canonicalization skipped due to max dots' )
286
290
return None
287
291
288
292
try :
289
293
ipaddress .ip_address (host )
290
294
except ValueError :
291
295
pass
292
296
else :
297
+ logger .info ('Hostname canonicalization skipped on IP address' )
293
298
return None
294
299
300
+ logger .debug1 ('Beginning hostname canonicalization' )
301
+
295
302
for domain in options .canonical_domains :
303
+ logger .debug1 (' Checking domain %s' , domain )
304
+
296
305
canon_host = f'{ host } .{ domain } '
297
306
298
307
try :
@@ -303,18 +312,28 @@ async def _canonicalize_host(loop: asyncio.AbstractEventLoop,
303
312
304
313
cname = addrinfo [0 ][3 ]
305
314
306
- if cname :
315
+ if cname and cname != canon_host :
316
+ logger .debug1 (' Checking CNAME rules for hostname %s '
317
+ 'with CNAME %s' , canon_host , cname )
318
+
307
319
for patterns in options .canonicalize_permitted_cnames :
308
320
host_pat , cname_pat = map (WildcardPatternList , patterns )
309
321
310
322
if host_pat .matches (canon_host ) and cname_pat .matches (cname ):
323
+ logger .info ('Hostname canonicalization to CNAME '
324
+ 'applied: %s -> %s' , options .host , cname )
311
325
return cname
312
326
327
+ logger .info ('Hostname canonicalization applied: %s -> %s' ,
328
+ options .host , canon_host )
329
+
313
330
return canon_host
314
331
315
332
if not options .canonicalize_fallback_local :
333
+ logger .info ('Hostname canonicalization failed (fallback disabled)' )
316
334
raise OSError (f'Unable to canonicalize hostname "{ host } "' )
317
335
336
+ logger .info ('Hostname canonicalization failed, using local resolver' )
318
337
return None
319
338
320
339
0 commit comments