While debugging why the <audio> tag behaves differently (at least in Mac Chrome) depending on specifying (1) a static link to a soundfile or (2) using the auth.wiki syntax ////2/sound.mp3 I notice quite a few differences in the headers.
(1) static: <audio controls="controls"><source src="/bgo/static/media/test.mp3" /></audio (2) download/auth.wiki() <audio controls="controls"><source src="/bgo/default/index/2/sound.mp3" /></audio> The two sets of settings can be shown by using curl, see below. Because essentially you ask a file to be served from the file system, you expect the same headers. But there not the same. It seems to me that extra headers and the cookie (and the session) in (2) are superfluous. And I discovered that the missing Last-Modified header causes the strange Chrome behavior. I fixed it by monkey-patching the gluon/tools.py media function inside auth.wiki. But I'm not sure if it's ok like this. Maybe the response.download function should be patched too? My patch is at the bottom. What do you think? Is this a good patch? I'm still on web2py version 2.2.1 ( will upgrade and test it on latest and trunk later, but I don't expect differences) Nico THE HEADERS (1) MacBook-Air-van-Nico:~ ncdegroot$ curl -I 127.0.0.1:8000/bgo/static/media/test.mp3 > HTTP/1.1 200 OK > Content-Length: 38660 > X-Powered-By: web2py > Last-Modified: Tue, 18 Dec 2012 11:20:41 GMT > Pragma: cache > Cache-Control: private > Content-Type: audio/mpeg > Date: Sun, 07 Apr 2013 19:19:57 GMT > Server: Rocket 1.2.5 Python/2.7.3 > Connection: keep-alive calling the download function() directly > MacBook-Air-van-Nico:~ ncdegroot$ curl -I > 127.0.0.1:8000/bgo/default/download/sound.mp3 > HTTP/1.1 404 NOT FOUND > Set-Cookie: session_id_bgo=127.0.0.1-8e6fd725-189d-41cd-bd6d-8c7408f66f98; > Path=/ > Content-Length: 536 > Content-Type: text/html; charset=UTF-8 > Date: Sun, 07 Apr 2013 15:44:30 GMT > Server: Rocket 1.2.5 Python/2.7.3 > Connection: keep-alive (2) MacBook-Air-van-Nico:~ ncdegroot$ curl -I 127.0.0.1:8000/bgo/default/index/2/sound.mp3 > HTTP/1.1 200 OK > Content-Length: 11310 > Content-Disposition: attachment; filename=wh-aam.mp3 > X-Powered-By: web2py > Set-Cookie: session_id_bgo=127.0.0.1-93f3ed51-7469-4ad0-8f47-ac8d5c71b7b1; > Path=/ > Expires: Sun, 07 Apr 2013 11:19:33 GMT > Pragma: no-cache > Cache-Control: no-store, no-cache, must-revalidate, post-check=0, > pre-check=0 > Content-Type: audio/mpeg > Date: Sun, 07 Apr 2013 11:19:33 GMT > Server: Rocket 1.2.5 Python/2.7.3 > Connection: keep-alive THE PATCH (concept) The differences can be fixed by patching the media() function in the auth.wiki part > gluon.tools.py: > > def media(self, id): > request, db = current.request, self.auth.db > media = db.wiki_media(id) > if media: > if self.manage_permissions: > page = db.wiki_page(media.wiki_page) > if not self.can_read(page): > return self.not_authorized(page) > request.args = [media.filename] > return current.response.download(request, db) > else: > raise HTTP(404) > > patched > > def media(self, id): > request, db = current.request, self.auth.db > media = db.wiki_media(id) > if media: > if self.manage_permissions: > page = db.wiki_page(media.wiki_page) > if not self.can_read(page): > return self.not_authorized(page) > request.args = [media.filename] > # patch ncdg > m = current.response.download(request, db) > current.session.forget() # get rid of the cookie > current.response.headers['Last-Modified'] = > (request.utcnow).strftime("%a, %d %b %Y %H:%M:%S GMT") > del current.response.headers['Content-Disposition'] > current.response.headers['Pragma'] = 'cache' > current.response.headers['Cache-Control'] = 'private' > return m > # /patch ncdg print headers > else: > raise HTTP(404) -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.