Then run it again. In an older machine it is possible to notice it is slower. What happens is that the server iterated over the string sending a single byte at a time to the client. So don’t forget to wrap the response in a better performance iterable like a list.

If the iterable yields more than one string the response body length will be the sum of all the string’s lengths like in thisscript:

#! /usr/bin/env pythonfromwsgiref.simple_serverimportmake_serverdefapplication(environ,start_response):response_body=['%s: %s'%(key,value)forkey,valueinsorted(environ.items())]response_body='\n'.join(response_body)# Adding strings to the response bodyresponse_body=['The Beggining\n','*'*30+'\n',response_body,'\n'+'*'*30,'\nThe End']# So the content-lenght is the sum of all string's lengthscontent_length=sum([len(s)forsinresponse_body])status='200 OK'response_headers=[('Content-Type','text/plain'),('Content-Length',str(content_length))]start_response(status,response_headers)returnresponse_bodyhttpd=make_server('localhost',8051,application)httpd.handle_request()