@@ -151,23 +151,25 @@ def handle(socket):
151
151
err (socket , "400" , "Bad Request" )
152
152
else : # find file in the document path
153
153
filePath = path
154
+ fileFound = True
154
155
# 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" )
169
172
return
170
-
171
173
# Responds the header first
172
174
socket .write ("HTTP/1.1 200 OK\r \n " )
173
175
contentType = "text/html"
0 commit comments