Remote media type detection fails when servers reject HEAD requests
Description
Image.from_url() and Audio.from_url() probe the content type for extensionless remote URLs using a HEAD request. Some servers serve the media normally with GET but return 405 Method Not Allowed or 501 Not Implemented for HEAD.
In that case, probe_remote_content_type() raises requests.HTTPError, so otherwise valid remote media cannot be classified or used.
Expected behavior
When HEAD returns 405 or 501, retry the probe with a streamed GET request and inspect its Content-Type header. Other HTTP errors should still be raised.
The fallback should retain the existing URL validation, redirect validation, DNS/SSRF protections, peer verification, timeout, and resource cleanup.
Verification
I reproduced this against the current main branch and have a focused patch with regression coverage for:
- HEAD 405 followed by a successful GET
- HEAD 501 followed by a successful GET
- no retry for unrelated errors such as 404
Is a PR welcome?
Source: 567-labs/instructor