Skip to content

Commit de7e862

Browse files
committed
Correct the error treating path not ended with '/' as folder. So relative paths in the html would be process correctly.
1 parent 0e2faf2 commit de7e862

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

ESP8266WebServer.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,25 @@ def handle(socket):
151151
err(socket, "400", "Bad Request")
152152
else: # find file in the document path
153153
filePath = path
154+
fileFound = True
154155
# find the file
155-
if not __fileExist(filePath):
156-
filePath = path + ("index.html" if path.endswith("/") else "/index.html")
157-
# find index.html in the path
158-
if not __fileExist(filePath):
159-
filePath = path + ("index.p.html" if path.endswith("/") else "/index.p.html")
160-
# find index.p.html in the path
161-
if not __fileExist(filePath): # no default html file found
162-
if notFoundHandler:
163-
notFoundHandler(socket)
164-
else:
165-
err(socket, "404", "Not Found")
166-
return
167-
socket.write("HTTP/1.1 302 Found\r\n")
168-
socket.write("Location: " + filePath + "\r\n\r\n")
156+
if not __fileExist(filePath):
157+
if not path.endswith("/"):
158+
fileFound = False
159+
else:
160+
filePath = path + "index.html"
161+
# find index.html in the path
162+
if not __fileExist(filePath):
163+
filePath = path + "index.p.html"
164+
# find index.p.html in the path
165+
if not __fileExist(filePath): # no default html file found
166+
fileFound = False
167+
if not fileFound: # file or default html file specified in path not found
168+
if notFoundHandler:
169+
notFoundHandler(socket)
170+
else:
171+
err(socket, "404", "Not Found")
169172
return
170-
171173
# Responds the header first
172174
socket.write("HTTP/1.1 200 OK\r\n")
173175
contentType = "text/html"

0 commit comments

Comments
 (0)