@@ -445,7 +445,7 @@ def handle(self):
445445        while  not  self .close_connection :
446446            self .handle_one_request ()
447447
448-     def  send_error (self , code , message = None , explain = None ):
448+     def  send_error (self , code , message = None , explain = None ,  * ,  range_size = None ):
449449        """Send and log an error reply. 
450450
451451        Arguments are 
@@ -456,6 +456,7 @@ def send_error(self, code, message=None, explain=None):
456456                   defaults to short entry matching the response code 
457457        * explain: a detailed message defaults to the long entry 
458458                   matching the response code. 
459+         * range_size: file size for use in content-range header 
459460
460461        This sends an error response (so it must be called before any 
461462        output has been generated), logs the error, and finally sends 
@@ -493,6 +494,8 @@ def send_error(self, code, message=None, explain=None):
493494            body  =  content .encode ('UTF-8' , 'replace' )
494495            self .send_header ("Content-Type" , self .error_content_type )
495496            self .send_header ('Content-Length' , str (len (body )))
497+         if  code  ==  HTTPStatus .REQUESTED_RANGE_NOT_SATISFIABLE  and  range_size :
498+             self .send_header ('Content-Range' , f'bytes */{ range_size }  ' )
496499        self .end_headers ()
497500
498501        if  self .command  !=  'HEAD'  and  body :
@@ -783,7 +786,7 @@ def send_head(self):
783786                    # none of the range values overlap the extent of 
784787                    # the resource 
785788                    f .close ()
786-                     self .send_error (HTTPStatus .REQUESTED_RANGE_NOT_SATISFIABLE )
789+                     self .send_error (HTTPStatus .REQUESTED_RANGE_NOT_SATISFIABLE ,  range_size = fs . st_size )
787790                    return  None 
788791                if  end  is  None  or  end  >=  fs .st_size :
789792                    end  =  fs .st_size  -  1 
0 commit comments