qoished

Python Server Script for Brotli decompression

Jan 23rd, 2026 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | Source Code | 0 0
  1. import http.server
  2. import socketserver
  3.  
  4. class UnityRequestHandler(http.server.SimpleHTTPRequestHandler):
  5.     def end_headers(self):
  6.         # Allow Cross-Origin Isolation (needed for many Unity games)
  7.         self.send_header("Cross-Origin-Opener-Policy", "same-origin")
  8.         self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
  9.        
  10.         # Tell the browser to decompress Brotli (.br) files
  11.         if self.path.endswith('.br'):
  12.             self.send_header('Content-Encoding', 'br')
  13.        
  14.         # Set correct MIME types for compressed files
  15.         if self.path.endswith('.js.br'):
  16.             self.send_header('Content-Type', 'application/javascript')
  17.         elif self.path.endswith('.wasm.br'):
  18.             self.send_header('Content-Type', 'application/wasm')
  19.         elif self.path.endswith('.data.br'):
  20.             self.send_header('Content-Type', 'application/octet-stream')
  21.            
  22.         super().end_headers()
  23.  
  24. PORT = 8000
  25. with socketserver.TCPServer(("", PORT), UnityRequestHandler) as httpd:
  26.     print(f"Server started at http://localhost:{PORT}")
  27.     httpd.serve_forever()
Tags: Script python
Advertisement
Add Comment
Please, Sign In to add comment