Skip to content

Commit a0f38f3

Browse files
committed
Added assets
1 parent 3e18480 commit a0f38f3

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

Diff for: IMG/mhttp_client.gif

71.7 KB
Loading

Diff for: IMG/mhttp_server.gif

70.3 KB
Loading

Diff for: Simple_Http_Server/README.md

+12-13
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44

55
# Simple HTTP Server
66

7-
Add a jpeg/png/gif file here if applicable
8-
9-
<!--An image is an illustration for your project, the tip here is using your sense of humour as much as you can :D
10-
11-
You can copy paste my markdown photo insert as following:
12-
<p align="center">
13-
<img src="your-source-is-here" width=40% height=40%>
14-
-->
15-
167
## 🛠️ Description
178
A simple HTTP server written using python sockets.
189

1910
## ⚙️ Languages or Frameworks Used
20-
This project is written in Python and has no other dependencies other than the Python Standard library.
11+
This project is written in Python 3.10 and has no other dependencies other than the Python Standard library.
2112

2213
## 🌟 How to run
23-
<!--Remove the below lines and add yours -->
24-
Steps on how to run the script along with suitable examples.
14+
Just run `python mhttp.py <your-desired-folder>`, where `<your-desired-folder>` is the folder which you need to serve. If you want to serve the current folder, just run `python mhttp.py`
2515

2616
## 📺 Demo
27-
Add a Screenshot/GIF showing the sample use of the script (jpeg/png/gif).
17+
<table>
18+
<tr>
19+
<td align="center">Server</td>
20+
<td align="center">Client</td>
21+
</tr>
22+
<tr>
23+
<td><img src="server.gif" alt="Server GIF"></td>
24+
<td><img src="client.gif" alt="Client GIF"></td>
25+
</tr>
26+
</table>
2827

2928
## 🤖 Author
3029
[Harish Kumar](https://github.com/harishtpj)

Diff for: Simple_Http_Server/mhttp.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@
1010

1111
def get_content(path):
1212
ext = "html"
13-
match path:
14-
case "/":
15-
try:
16-
with open(FOLDER + "/index.html", "r") as f:
17-
content = f.read()
18-
except FileNotFoundError:
19-
content = "The Server is working! but there is no index.html file to render"
20-
case _:
21-
try:
22-
with open(FOLDER + path, "r") as f:
23-
if Path(FOLDER + path).suffix != ".html":
24-
ext = "plain"
25-
content = f.read()
26-
except FileNotFoundError:
27-
return 404, "File not found", ext
13+
if path == "/":
14+
try:
15+
with open(FOLDER + "/index.html", "r") as f:
16+
content = f.read()
17+
except FileNotFoundError:
18+
content = "The Server is working! but there is no index.html file to render"
19+
else:
20+
try:
21+
with open(FOLDER + path, "r") as f:
22+
if Path(FOLDER + path).suffix != ".html":
23+
ext = "plain"
24+
content = f.read()
25+
except FileNotFoundError:
26+
return 404, "File not found", ext
2827
return 200, content, ext
2928

3029
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:

0 commit comments

Comments
 (0)