def handle(self, path, environ, start_response): try: filename = basename(path) response = Response() response.content_type = 'text/x-igc' response.headerlist.append(('Content-Disposition', 'attachment;filename={}'.format(filename))) response.body_file = open_file(filename) return response(environ, start_response) except IOError: return HTTPNotFound()(environ, start_response) except: return HTTPInternalServerError()(environ, start_response)
def handle(self, path, environ, start_response): try: path = os.path.join(self.base_dir, path) response = Response() content_type, _ = mimetypes.guess_type(path) if content_type: response.content_type = content_type response.body_file = file(path) return response(environ, start_response) except IOError: return HTTPNotFound()(environ, start_response) except: return HTTPInternalServerError()(environ, start_response)