From cacc9ac7b1af9e0ac80431597a0d8b4adeebd721 Mon Sep 17 00:00:00 2001
From: robk-org <robk-org@allmydata.com>
Date: Wed, 11 Jul 2007 15:26:47 -0700
Subject: [PATCH] include the filename on URI-link urls for files

this is likely to induce browsers to do more useful things with the result
than they would when given neither content-type nor filename.  (i.e. they
can guess that a .jpg file is an image, even with a bogus content type)
---
 src/allmydata/webish.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py
index 2da53fd8..8c13a1b8 100644
--- a/src/allmydata/webish.py
+++ b/src/allmydata/webish.py
@@ -83,13 +83,8 @@ class Directory(rend.Page):
             delete = "-"
         ctx.fillSlots("delete", delete)
 
+        # build the base of the uri_link link url
         uri_link = urllib.quote(target.get_uri().replace("/", "!"))
-        childdata = [T.a(href="%s?t=json" % name)["JSON"], ", ",
-                     T.a(href="%s?t=uri" % name)["URI"], ", ",
-                     T.a(href="%s?t=readonly-uri" % name)["readonly-URI"], ", ",
-                     T.a(href="/uri/%s" % uri_link)["URI-link"],
-                     ]
-        ctx.fillSlots("data", childdata)
 
         if IFileNode.providedBy(target):
             # file
@@ -112,6 +107,9 @@ class Directory(rend.Page):
                 size = "?"
             ctx.fillSlots("size", size)
 
+            # if we're a file, add the filename to the uri_link url
+            uri_link += '?%s' % (urllib.urlencode({'filename': name}),)
+
         elif IDirectoryNode.providedBy(target):
             # directory
             subdir_url = urllib.quote(name)
@@ -125,6 +123,14 @@ class Directory(rend.Page):
             ctx.fillSlots("size", "-")
         else:
             raise RuntimeError("unknown thing %s" % (target,))
+
+        childdata = [T.a(href="%s?t=json" % name)["JSON"], ", ",
+                     T.a(href="%s?t=uri" % name)["URI"], ", ",
+                     T.a(href="%s?t=readonly-uri" % name)["readonly-URI"], ", ",
+                     T.a(href="/uri/%s" % uri_link)["URI-link"],
+                     ]
+        ctx.fillSlots("data", childdata)
+
         return ctx.tag
 
     def render_forms(self, ctx, data):
-- 
2.45.2