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