Reputation: 2551
I am creating an HTTP client downloader in Python. I am able to correctly download a file such as http://www.google.com/images/srpr/logo11w.png just fine. However, I'm not sure what to actually name the thing.
There is of course the filename at the end of the URL, but is this always reliable?
Upvotes: 0
Views: 34
Reputation: 1266
If I recall correctly, wget uses the following heuristic:
Content-Disposition
header exists, get the filename from there.http://myserver/filename
), use that.http://www.google.com
), derive the filename from the Content-Type
header (such as index.html
for text/html
) index (1).html
, or overwrite, depending on configuration.There are plenty of other flags that control other heuristics, such as creating .html for ASP/DHTML content-types.
In short, it really depends how far you want to go. For most people, doing the first two + basic Content-Type->name mapping should be enough.
Upvotes: 1