Ticket #3083 (closed defect: fixed)
Bad handling of URLs in IE5/6 when downloading files in raw format
| Reported by: | Christophe.Muller@… | Owned by: | cboos |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.11 |
| Component: | version control/browser | Version: | 0.9.3 |
| Severity: | normal | Keywords: | IE, raw, HTTP |
| Cc: |
Description
Hello,
The problem really lies in Internet Explorer I think and not trac but the fact that the URL for original format links would be of the form ".../file.exe?format=raw" (or any other binary type) makes IE want to save a file called "file" without the extension, and thus... that cannot be ran afterwards. It also happens for example when the URL is ".../file.tgz?format=raw" in which case IE renames it to "file.tar"!???! I have tried to look for solutions on the web but could only find people with the same problem. One of the suggestions, though, was to add to the HTTP header a Content-Disposition field which forces 1) a download and 2) a filename (this HTTP feature is described in RFC 1806).
I have patched my own working copy of trac with the following code (file versioncontrol/web_ui/browser.py) in _render_file:
format = req.args.get('format')
if format in ['raw', 'txt']:
req.send_response(200)
if format == 'raw':
filename=node.path.split('/').pop()
req.send_header('Content-Disposition', 'attachment;' + 'filename=' + filename)
req.send_header('Content-Type',
format == 'txt' and 'text/plain' or mime_type)
req.send_header('Content-Length', node.content_length)
...
And it seems to do the trick for IE: when clicking on raw versions, IE now proposes to save the file with exactly the file name that we send in the HTTP header.
I'm not sure you will want to fix IE bugs with workarounds :-) but just in case, I fill this ticket. Thanks for the attention.
Cheers,
Christophe.
= Ubuntu is an ancient African word, meaning "I can't configure Slackware". =


