olan-https 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- olan_https-0.1.0/PKG-INFO +5 -0
- olan_https-0.1.0/https/__init__.py +0 -0
- olan_https-0.1.0/https/server.py +88 -0
- olan_https-0.1.0/olan_https.egg-info/PKG-INFO +5 -0
- olan_https-0.1.0/olan_https.egg-info/SOURCES.txt +7 -0
- olan_https-0.1.0/olan_https.egg-info/dependency_links.txt +1 -0
- olan_https-0.1.0/olan_https.egg-info/top_level.txt +1 -0
- olan_https-0.1.0/pyproject.toml +12 -0
- olan_https-0.1.0/setup.cfg +4 -0
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# https/server.py
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import http.server
|
|
5
|
+
import os
|
|
6
|
+
import ssl
|
|
7
|
+
import subprocess
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def getCertificate():
|
|
12
|
+
directory = Path.home() / ".https"
|
|
13
|
+
directory.mkdir(exist_ok=True)
|
|
14
|
+
|
|
15
|
+
cert = directory / "cert.pem"
|
|
16
|
+
key = directory / "key.pem"
|
|
17
|
+
|
|
18
|
+
if not cert.exists() or not key.exists():
|
|
19
|
+
print("Generating HTTPS certificate...")
|
|
20
|
+
|
|
21
|
+
subprocess.run([
|
|
22
|
+
"openssl",
|
|
23
|
+
"req",
|
|
24
|
+
"-x509",
|
|
25
|
+
"-newkey", "rsa:2048",
|
|
26
|
+
"-keyout", str(key),
|
|
27
|
+
"-out", str(cert),
|
|
28
|
+
"-days", "3650",
|
|
29
|
+
"-nodes",
|
|
30
|
+
"-subj", "/CN=localhost",
|
|
31
|
+
], check=True)
|
|
32
|
+
|
|
33
|
+
print(f"Certificate created: {cert}")
|
|
34
|
+
print(f"Key created: {key}")
|
|
35
|
+
|
|
36
|
+
return cert, key
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main():
|
|
40
|
+
parser = argparse.ArgumentParser(
|
|
41
|
+
description="Serve the current directory over HTTPS."
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
parser.add_argument(
|
|
45
|
+
"port",
|
|
46
|
+
nargs="?",
|
|
47
|
+
type=int,
|
|
48
|
+
default=8443
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
parser.add_argument(
|
|
52
|
+
"--bind",
|
|
53
|
+
"-b",
|
|
54
|
+
default=""
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
args = parser.parse_args()
|
|
58
|
+
|
|
59
|
+
cert, key = getCertificate()
|
|
60
|
+
|
|
61
|
+
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
62
|
+
context.load_cert_chain(certfile=cert, keyfile=key)
|
|
63
|
+
|
|
64
|
+
server = http.server.ThreadingHTTPServer(
|
|
65
|
+
(args.bind, args.port),
|
|
66
|
+
http.server.SimpleHTTPRequestHandler
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
server.socket = context.wrap_socket(
|
|
70
|
+
server.socket,
|
|
71
|
+
server_side=True
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
host = args.bind or "0.0.0.0"
|
|
75
|
+
|
|
76
|
+
print(f"Serving HTTPS on {host} port {args.port}...")
|
|
77
|
+
print(f"https://localhost:{args.port}/")
|
|
78
|
+
|
|
79
|
+
try:
|
|
80
|
+
server.serve_forever()
|
|
81
|
+
except KeyboardInterrupt:
|
|
82
|
+
print("\nShutting down...")
|
|
83
|
+
finally:
|
|
84
|
+
server.server_close()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
https
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "olan-https"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A simple HTTPS server for Python"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
|
|
11
|
+
[tool.setuptools.packages.find]
|
|
12
|
+
include = ["https*"]
|