@@ -152,14 +152,15 @@ def switch_to_websocket(self) -> None:
152
152
153
153
def on_request_complete (self ) -> Union [socket .socket , bool ]:
154
154
path = self .request .path or b'/'
155
- # Try route
156
155
teardown = self ._try_route (path )
157
- if teardown :
156
+ # Try route signaled to teardown
157
+ # or if it did find a valid route
158
+ if teardown or self .route is not None :
158
159
return teardown
159
160
# No-route found, try static serving if enabled
160
- teardown = self ._try_static_file ( path )
161
- if teardown :
162
- return teardown
161
+ if self .flags . enable_static_server :
162
+ self . _try_static_or_404 ( path )
163
+ return True
163
164
# Catch all unhandled web server requests, return 404
164
165
self .client .queue (NOT_FOUND_RESPONSE_PKT )
165
166
return True
@@ -299,13 +300,10 @@ def _try_route(self, path: bytes) -> bool:
299
300
return True
300
301
return False
301
302
302
- def _try_static_file (self , path : bytes ) -> bool :
303
- if self .flags .enable_static_server :
304
- path = text_ (path ).split ('?' , 1 )[0 ]
305
- self .client .queue (
306
- self .read_and_build_static_file_response (
307
- self .flags .static_server_dir + path ,
308
- ),
309
- )
310
- return True
311
- return False
303
+ def _try_static_or_404 (self , path : bytes ) -> None :
304
+ path = text_ (path ).split ('?' , 1 )[0 ]
305
+ self .client .queue (
306
+ self .read_and_build_static_file_response (
307
+ self .flags .static_server_dir + path ,
308
+ ),
309
+ )
0 commit comments