-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhttps-file-server.py
More file actions
48 lines (46 loc) · 2.06 KB
/
https-file-server.py
File metadata and controls
48 lines (46 loc) · 2.06 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import http.server
import socket
import ssl
import os
import webbrowser
from pystyle import Anime, Colorate, Colors, Center, System, Write
port = 80
server_address = ('0.0.0.0', port)
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
print(Center.XCenter(f"Server running on https://localhost:{port}"))
webbrowser.open(f"https://localhost:{port}")
info = '''
╔═════════════════════════════════════════════════╗
║ HTTP FILE SERVER ║
║ coded by CHAINSKI ║
║ For Educational Purposes Only ║
║ Made with Python 3 ║
╚═════════════════════════════════════════════════╝
'''
print(Colorate.Diagonal(Colors.red_to_white, Center.XCenter(info)))
class CORSHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
extensions_map = {
'': 'application/octet-stream',
'.manifest': 'text/cache-manifest',
'.html': 'text/html',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.svg': 'image/svg+xml',
'.css': 'text/css',
'.js': 'application/x-javascript',
'.wasm': 'application/wasm',
'.json': 'application/json',
'.xml': 'application/xml',
}
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
http.server.SimpleHTTPRequestHandler.end_headers(self)
httpd = http.server.HTTPServer(server_address, CORSHTTPRequestHandler)
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.check_hostname = False
ctx.load_cert_chain(certfile='cert.pem') # with key inside
httpd.socket = ctx.wrap_socket(httpd.socket, server_side=True)
httpd.serve_forever()