@@ -553,6 +553,13 @@ class HTTPServer: # pylint: disable=too-many-instance-attributes
553553 :py:class:`Request` and :py:class:`Response` object which represents the
554554 incoming request and the outgoing response which happened during the lifetime
555555 of the server.
556+
557+ .. py:attribute:: no_handler_status_code
558+
559+ Attribute containing the http status code (int) which will be the response
560+ status when no matcher is found for the request. By default, it is set to *500*
561+ but it can be overridden to any valid http status code such as *404* if needed.
562+
556563 """
557564
558565 DEFAULT_LISTEN_HOST = "localhost"
@@ -581,6 +588,7 @@ def __init__(self, host=DEFAULT_LISTEN_HOST, port=DEFAULT_LISTEN_PORT, ssl_conte
581588 self .default_waiting_settings = WaitingSettings ()
582589 self ._waiting_settings = copy (self .default_waiting_settings )
583590 self ._waiting_result = queue .LifoQueue (maxsize = 1 )
591+ self .no_handler_status_code = 500
584592
585593 def clear (self ):
586594 """
@@ -593,6 +601,7 @@ def clear(self):
593601 self .clear_log ()
594602 self .clear_all_handlers ()
595603 self .permanently_failed = False
604+ self .no_handler_status_code = 500
596605
597606 def clear_assertions (self ):
598607 """
@@ -941,7 +950,7 @@ def respond_nohandler(self, request: Request):
941950 self ._set_waiting_result (False )
942951 text = "No handler found for request {!r}.\n " .format (request )
943952 self .add_assertion (text + self .format_matchers ())
944- return Response ("No handler found for this request" , 500 )
953+ return Response ("No handler found for this request" , self . no_handler_status_code )
945954
946955 def respond_permanent_failure (self ):
947956 """
0 commit comments