Quick fix that adresses #1
This commit is contained in:
35
README.md
35
README.md
@@ -1,2 +1,37 @@
|
|||||||
# PyWebServer
|
# PyWebServer
|
||||||
|
|
||||||
|
## Installing
|
||||||
|
Installing and running PyWebServer is very simple.
|
||||||
|
Assuming you're running Linux:
|
||||||
|
```bash
|
||||||
|
git clone https://git.novacow.ch/Nova/PyWebServer.git
|
||||||
|
cd ./PyWebServer/
|
||||||
|
```
|
||||||
|
Windows users, make sure you have installed Git, from there:
|
||||||
|
```powershell
|
||||||
|
git clone https://git.novacow.ch/Nova/PyWebServer.git
|
||||||
|
Set-Location .\PyWebServer\
|
||||||
|
```
|
||||||
|
From here, you should check from what directory you want to store the content in.
|
||||||
|
In this example, we'll use `./html/` (or `.\html\` for Windows users) from the perspective of the PyWebServer root dir.
|
||||||
|
To create this directory, do this:
|
||||||
|
```bash
|
||||||
|
mkdir ./html/
|
||||||
|
```
|
||||||
|
(This applies to both Windows and Linux)
|
||||||
|
Then, open `pywebsrv.conf` in your favorite text editor and change the `directory` key to the full path to the `./html/` you just created.
|
||||||
|
After that, put your files in and run this:
|
||||||
|
Linux:
|
||||||
|
```bash
|
||||||
|
python3 /path/to/pywebsrv.py
|
||||||
|
```
|
||||||
|
Windows:
|
||||||
|
```powershell
|
||||||
|
# If you have installed Python via the Microsoft Store:
|
||||||
|
python3 \path\to\pywebsrv.py
|
||||||
|
# Via the python.org website:
|
||||||
|
py \path\to\pywebsrv.py
|
||||||
|
```
|
||||||
|
|
||||||
|
## SSL Support
|
||||||
|
Currently PyWebServer warns about AutoCertGen not being installed. AutoCertGen currently is very unstable at the moment,
|
||||||
|
13
pywebsrv.py
13
pywebsrv.py
@@ -45,8 +45,8 @@ class FileHandler:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, base_dir=None):
|
def __init__(self, base_dir=None):
|
||||||
self.base_dir = base_dir or os.path.join(os.getcwd(), "html")
|
|
||||||
self.config_path = os.path.join(os.getcwd(), self.CONFIG_FILE)
|
self.config_path = os.path.join(os.getcwd(), self.CONFIG_FILE)
|
||||||
|
self.base_dir = self.read_config("directory")
|
||||||
|
|
||||||
def check_first_run(self):
|
def check_first_run(self):
|
||||||
if not os.path.isfile(self.config_path):
|
if not os.path.isfile(self.config_path):
|
||||||
@@ -125,6 +125,11 @@ class FileHandler:
|
|||||||
or option == "allow-nohost"
|
or option == "allow-nohost"
|
||||||
):
|
):
|
||||||
return bool(int(value))
|
return bool(int(value))
|
||||||
|
if option == "directory":
|
||||||
|
if value == "<Enter directory here>":
|
||||||
|
print("FATAL: You haven't set up PyWebServer! Please edit pywebsrv.conf!")
|
||||||
|
exit(1)
|
||||||
|
return value
|
||||||
return value
|
return value
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -150,11 +155,11 @@ class RequestParser:
|
|||||||
"""Parses the HTTP request line."""
|
"""Parses the HTTP request line."""
|
||||||
try:
|
try:
|
||||||
method, path, version = line.split(" ")
|
method, path, version = line.split(" ")
|
||||||
|
except ValueError:
|
||||||
|
return None, None, None
|
||||||
if path.endswith("/"):
|
if path.endswith("/"):
|
||||||
path += "index.html"
|
path += "index.html"
|
||||||
return method, path, version
|
return method, path, version
|
||||||
except ValueError:
|
|
||||||
return None, None, None
|
|
||||||
|
|
||||||
def is_method_allowed(self, method):
|
def is_method_allowed(self, method):
|
||||||
"""
|
"""
|
||||||
@@ -251,7 +256,7 @@ class WebServer:
|
|||||||
)
|
)
|
||||||
self.http_405_html = (
|
self.http_405_html = (
|
||||||
"<html><head><title>HTTP 405 - PyWebServer</title></head>"
|
"<html><head><title>HTTP 405 - PyWebServer</title></head>"
|
||||||
"<body><center><h1>HTTP 404 - Method not allowed</h1><p>Running PyWebServer/1.1</p>"
|
"<body><center><h1>HTTP 405 - Method not allowed</h1><p>Running PyWebServer/1.1</p>"
|
||||||
"</center></body></html>"
|
"</center></body></html>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user