File size: 821 Bytes
c1e4f50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""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()