Xaqron
Xaqron

Reputation: 30867

How browser find out file name in downloads?

You may say it will look at Content-Disposition for file name, but I'm talking about where there's nothing in that header and also URL is not so straight forward like http://website.com/myfile.zip. I leave some examples here but wondering how browser (I use FireFox) find out the right name in save as dialog. Does it know the URL syntax for famous websites ?

download links in sourceforge.net
download links in cnet.com
download from your own localhost

I used Fiddler2 for reverse engineering.

URL: http://mesh.dl.sourceforge.net/project/npp-plugins/Function List/FunctionList Plugin v2.1/FunctionList_2_1_UNI_dll.zip

Fiddler output sample:

HTTP/1.1 200 OK
Date: Sat, 13 Nov 2010 22:46:31 GMT
Server: Apache/2.2.9 (Debian)
Last-Modified: Thu, 18 Feb 2010 04:35:26 GMT
ETag: "142a602c-1fe24-47fd87eed7f80"
Accept-Ranges: bytes
Content-Length: 130596
Connection: close
Content-Type: application/zip

EDIT: Problem is Content-Disposition is not set at final response, instead it at one of redirection. HttpWebRespose header contains last response header (AllowAutoRedirect = true). I need to keep track of all responses and check if there is a Content-Disposition then remember it. How ?

Upvotes: 4

Views: 2684

Answers (2)

Yann Ramin
Yann Ramin

Reputation: 33197

If its not the filename attribute of the Content-Disposition header, its likely some HTTP 302 redirect, or a hidden iframe with the file download.

Upvotes: 0

Alberto Martinez
Alberto Martinez

Reputation: 2670

The do use content-disposition or any other standard method. See this example I just get from SourceForge using Live HTTP Headers:

HTTP/1.1 302 Found
X-Powered-By: PHP/5.2.9
Content-Disposition: attachment; filename="FunctionList_2_1_UNI_dll.zip"
Location: http://mesh.dl.sourceforge.net/project/npp-plugins/Function%20List/FunctionList%20Plugin%20v2.1/FunctionList_2_1_UNI_dll.zip
Content-Type: text/html
Content-Length: 0
Date: Sat, 13 Nov 2010 22:30:00 GMT
Server: lighttpd/1.4.26

Note that they also use a redirect, maybe you get confused by that.

Upvotes: 7

Related Questions