Skip to content

Commit 8579948

Browse files
committed
Completed Assignment 3
1 parent d458487 commit 8579948

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

http_server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ def response_path(path):
9090
"""
9191
home_path = os.getcwd() + "/webroot" + path
9292

93+
# URI is a directory, then return plain-text listing of the contents and mime_type
9394
if os.path.isdir(home_path):
94-
mime_type = b"text/plain"
9595
content = ('\r\n, '.join(os.listdir(home_path))).encode('utf8')
96+
mime_type = b"text/plain"
9697

98+
# URI is a file, then return contents of file and mime_type
9799
elif os.path.isfile(home_path):
98-
mime_type = mimetypes.guess_type(path)[0].encode('utf8')
99100
with open(home_path, 'rb') as file:
100101
content = file.read()
102+
mime_type = mimetypes.guess_type(path)[0].encode('utf8')
101103

102104
# Raise a NameError if the requested content is not present under webroot.
103105
else:

0 commit comments

Comments
 (0)