Skip to content

Instantly share code, notes, and snippets.

@naoyeye
Created August 20, 2012 23:09
Show Gist options
  • Save naoyeye/3409064 to your computer and use it in GitHub Desktop.
Save naoyeye/3409064 to your computer and use it in GitHub Desktop.
import web
import mimetypes
class public:
def GET(self):
public_dir = 'public'
try:
file_name = web.ctx.path.split('/')[-1]
web.header('Content-type', mime_type(file_name))
return open(public_dir + web.ctx.path, 'rb').read()
except IOError:
raise web.notfound()
def mime_type(filename):
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment