@@ -2632,14 +2632,17 @@ def preset_add(
26322632 from .extensions import detect_archive_format as _det_fmt
26332633
26342634 with tempfile .TemporaryDirectory () as tmpdir :
2635- archive_fmt = _det_fmt (from_url )
26362635 final_url = from_url
2636+ archive_fmt = ""
26372637 try :
26382638 with urllib .request .urlopen (from_url , timeout = 60 ) as response :
26392639 final_url = response .geturl ()
2640+ content_type = response .headers .get ("Content-Type" , "" )
2641+ # Prefer the post-redirect URL for format detection;
2642+ # fall back to the original URL only as a last hint.
2643+ archive_fmt = _det_fmt (final_url , content_type )
26402644 if not archive_fmt :
2641- content_type = response .headers .get ("Content-Type" , "" )
2642- archive_fmt = _det_fmt (final_url , content_type )
2645+ archive_fmt = _det_fmt (from_url )
26432646 archive_data = response .read ()
26442647 except urllib .error .URLError as e :
26452648 console .print (f"[red]Error:[/red] Failed to download: { e } " )
@@ -3657,18 +3660,22 @@ def extension_add(
36573660 console .print ("Only install extensions from sources you trust.\n " )
36583661 console .print (f"Downloading from { from_url } ..." )
36593662
3660- # Download archive to temp location; detect format from URL or Content-Type.
3663+ # Download archive to temp location; detect format from the
3664+ # post-redirect URL (with Content-Type fallback), only using
3665+ # the original URL as a last hint.
36613666 download_dir = project_root / ".specify" / "extensions" / ".cache" / "downloads"
36623667 download_dir .mkdir (parents = True , exist_ok = True )
3663- archive_fmt = detect_archive_format (from_url )
3668+ final_url = from_url
3669+ archive_fmt = ""
36643670 archive_path = None
36653671
36663672 try :
36673673 with urllib .request .urlopen (from_url , timeout = 60 ) as response :
36683674 final_url = response .geturl ()
3675+ content_type = response .headers .get ("Content-Type" , "" )
3676+ archive_fmt = detect_archive_format (final_url , content_type )
36693677 if not archive_fmt :
3670- content_type = response .headers .get ("Content-Type" , "" )
3671- archive_fmt = detect_archive_format (final_url , content_type )
3678+ archive_fmt = detect_archive_format (from_url )
36723679 archive_data = response .read ()
36733680
36743681 # Re-validate scheme after any redirect (scheme-downgrade guard).
0 commit comments