@@ -115,6 +115,12 @@ def do_LATINONEHEADER(self):
115115 body = self .headers ['x-special-incoming' ].encode ('utf-8' )
116116 self .wfile .write (body )
117117
118+ def do_SEND_ERROR (self ):
119+ self .send_error (int (self .path [1 :]))
120+
121+ def do_HEAD (self ):
122+ self .send_error (int (self .path [1 :]))
123+
118124 def setUp (self ):
119125 BaseTestCase .setUp (self )
120126 self .con = http .client .HTTPConnection (self .HOST , self .PORT )
@@ -236,6 +242,44 @@ def test_error_content_length(self):
236242 data = res .read ()
237243 self .assertEqual (int (res .getheader ('Content-Length' )), len (data ))
238244
245+ def test_send_error (self ):
246+ allow_transfer_encoding_codes = (HTTPStatus .NOT_MODIFIED ,
247+ HTTPStatus .RESET_CONTENT )
248+ for code in (HTTPStatus .NO_CONTENT , HTTPStatus .NOT_MODIFIED ,
249+ HTTPStatus .PROCESSING , HTTPStatus .RESET_CONTENT ,
250+ HTTPStatus .SWITCHING_PROTOCOLS ):
251+ self .con .request ('SEND_ERROR' , '/{}' .format (code ))
252+ res = self .con .getresponse ()
253+ self .assertEqual (code , res .status )
254+ self .assertEqual (None , res .getheader ('Content-Length' ))
255+ self .assertEqual (None , res .getheader ('Content-Type' ))
256+ if code not in allow_transfer_encoding_codes :
257+ self .assertEqual (None , res .getheader ('Transfer-Encoding' ))
258+
259+ data = res .read ()
260+ self .assertEqual (b'' , data )
261+
262+ def test_head_via_send_error (self ):
263+ allow_transfer_encoding_codes = (HTTPStatus .NOT_MODIFIED ,
264+ HTTPStatus .RESET_CONTENT )
265+ for code in (HTTPStatus .OK , HTTPStatus .NO_CONTENT ,
266+ HTTPStatus .NOT_MODIFIED , HTTPStatus .RESET_CONTENT ,
267+ HTTPStatus .SWITCHING_PROTOCOLS ):
268+ self .con .request ('HEAD' , '/{}' .format (code ))
269+ res = self .con .getresponse ()
270+ self .assertEqual (code , res .status )
271+ if code == HTTPStatus .OK :
272+ self .assertTrue (int (res .getheader ('Content-Length' )) > 0 )
273+ self .assertIn ('text/html' , res .getheader ('Content-Type' ))
274+ else :
275+ self .assertEqual (None , res .getheader ('Content-Length' ))
276+ self .assertEqual (None , res .getheader ('Content-Type' ))
277+ if code not in allow_transfer_encoding_codes :
278+ self .assertEqual (None , res .getheader ('Transfer-Encoding' ))
279+
280+ data = res .read ()
281+ self .assertEqual (b'' , data )
282+
239283
240284class RequestHandlerLoggingTestCase (BaseTestCase ):
241285 class request_handler (BaseHTTPRequestHandler ):
0 commit comments