Skip to content

Commit

Permalink
Correct the error treating path not ended with '/' as folder. So rela…
Browse files Browse the repository at this point in the history
…tive paths in the html would be process correctly.
  • Loading branch information
codemee committed Sep 3, 2020
1 parent 0e2faf2 commit de7e862
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions ESP8266WebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,25 @@ def handle(socket):
err(socket, "400", "Bad Request")
else: # find file in the document path
filePath = path
fileFound = True
# find the file
if not __fileExist(filePath):
filePath = path + ("index.html" if path.endswith("/") else "/index.html")
# find index.html in the path
if not __fileExist(filePath):
filePath = path + ("index.p.html" if path.endswith("/") else "/index.p.html")
# find index.p.html in the path
if not __fileExist(filePath): # no default html file found
if notFoundHandler:
notFoundHandler(socket)
else:
err(socket, "404", "Not Found")
return
socket.write("HTTP/1.1 302 Found\r\n")
socket.write("Location: " + filePath + "\r\n\r\n")
if not __fileExist(filePath):
if not path.endswith("/"):
fileFound = False
else:
filePath = path + "index.html"
# find index.html in the path
if not __fileExist(filePath):
filePath = path + "index.p.html"
# find index.p.html in the path
if not __fileExist(filePath): # no default html file found
fileFound = False
if not fileFound: # file or default html file specified in path not found
if notFoundHandler:
notFoundHandler(socket)
else:
err(socket, "404", "Not Found")
return

# Responds the header first
socket.write("HTTP/1.1 200 OK\r\n")
contentType = "text/html"
Expand Down

0 comments on commit de7e862

Please sign in to comment.