"""Serve the archive and its LFS-backed files from the Space's own origin.""" import os from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer class Handler(SimpleHTTPRequestHandler): extensions_map = { **SimpleHTTPRequestHandler.extensions_map, '.gz': 'application/gzip', '.woff2': 'font/woff2', '.ttf': 'font/ttf', } def end_headers(self): # Paths are stable across updates, so all files must be revalidated. # .gz files stay gzip payloads, with no Content-Encoding transformation. self.send_header('Cache-Control', 'no-cache') super().end_headers() if __name__ == '__main__': ThreadingHTTPServer( (os.environ.get('HOST', '0.0.0.0'), int(os.environ.get('PORT', '7860'))), Handler, ).serve_forever()