def _content_length_rewriter(state):
 state.body = list(state.body)
 length = sum((len(block) for block in state.body))
 if (state.status_code in constants.NO_BODY_RESPONSE_STATUSES):
  state.body = []
  del state.headers['Content-Length']
 elif (state.environ.get('REQUEST_METHOD') == 'HEAD'):
  if length:
   logging.warning('Dropping unexpected body in response to HEAD request')
   state.body = []
 elif ((not state.allow_large_response) and (length > constants.MAX_RUNTIME_RESPONSE_SIZE)):
  logging.error('Response too large: %d, max is %d', length, constants.MAX_RUNTIME_RESPONSE_SIZE)
  new_response = ('HTTP response was too large: %d. The limit is: %d.\n' % (length, constants.MAX_RUNTIME_RESPONSE_SIZE))
  state.status = '500 Internal Server Error'
  state.headers['Content-Type'] = 'text/html'
  state.headers['Content-Length'] = str(len(new_response))
  state.body = [new_response]
 else:
  state.headers['Content-Length'] = str(length)

def _content_length_rewriter ( state ) : state . body = list ( state . body ) length = sum ( ( len ( block ) for block in state . body ) ) if ( state . status_code in constants . NO_BODY_RESPONSE_STATUSES ) : state . body = [ ] del state . headers [ 'Content-Length' ] elif ( state . environ . get ( 'REQUEST_METHOD' ) == 'HEAD' ) : if length : logging . warning ( 'Dropping unexpected body in response to HEAD request' ) state . body = [ ] elif ( ( not state . allow_large_response ) and ( length > constants . MAX_RUNTIME_RESPONSE_SIZE ) ) : logging . error ( 'Response too large: %d, max is %d' , length , constants . MAX_RUNTIME_RESPONSE_SIZE ) new_response = ( 'HTTP response was too large: %d. The limit is: %d.\n' % ( length , constants . MAX_RUNTIME_RESPONSE_SIZE ) ) state . status = '500 Internal Server Error' state . headers [ 'Content-Type' ] = 'text/html' state . headers [ 'Content-Length' ] = str ( len ( new_response ) ) state . body = [ new_response ] else : state . headers [ 'Content-Length' ] = str ( length )
rewrite the content-length header .