@@ -49,7 +49,8 @@ def route(self, path):
49
49
path = re .sub ("^http://" , "/" , path ) # Remove begining http for chrome extension .bit access
50
50
51
51
if self .env ["REQUEST_METHOD" ] == "OPTIONS" :
52
- self .sendHeader ()
52
+ content_type = self .getContentType (path )
53
+ self .sendHeader (content_type = content_type )
53
54
return ""
54
55
55
56
if path == "/" :
@@ -137,8 +138,8 @@ def sendHeader(self, status=200, content_type="text/html", extra_headers=[]):
137
138
headers .append (("Version" , "HTTP/1.1" ))
138
139
headers .append (("Connection" , "Keep-Alive" ))
139
140
headers .append (("Keep-Alive" , "max=25, timeout=30" ))
140
- if content_type == "application/json " :
141
- headers .append (("Access-Control-Allow-Origin" , "*" )) # Allow json access only on json content
141
+ if content_type != "text/html " :
142
+ headers .append (("Access-Control-Allow-Origin" , "*" )) # Allow json access on non-html files
142
143
# headers.append(("Content-Security-Policy", "default-src 'self' data: 'unsafe-inline' ws://127.0.0.1:* http://127.0.0.1:* wss://tracker.webtorrent.io; sandbox allow-same-origin allow-top-navigation allow-scripts")) # Only local connections
143
144
if self .env ["REQUEST_METHOD" ] == "OPTIONS" :
144
145
# Allow json access
@@ -380,11 +381,11 @@ def actionFile(self, file_path, block_size=64 * 1024, send_header=True):
380
381
if range :
381
382
range_start = int (re .match (".*?([0-9]+)" , range ).group (1 ))
382
383
if re .match (".*?-([0-9]+)" , range ):
383
- range_end = int (re .match (".*?-([0-9]+)" , range ).group (1 ))+ 1
384
+ range_end = int (re .match (".*?-([0-9]+)" , range ).group (1 )) + 1
384
385
else :
385
386
range_end = file_size
386
387
extra_headers ["Content-Length" ] = str (range_end - range_start )
387
- extra_headers ["Content-Range" ] = "bytes %s-%s/%s" % (range_start , range_end - 1 , file_size )
388
+ extra_headers ["Content-Range" ] = "bytes %s-%s/%s" % (range_start , range_end - 1 , file_size )
388
389
if range :
389
390
status = 206
390
391
else :
0 commit comments