new_contents: import re
  
  class StripWhitespaceMiddleware(object):
      """
      Strips leading and trailing whitespace from response content.
      """
  
      def __init__(self):
          self.whitespace = re.compile('^\s*\n', re.MULTILINE)
          self.whitespace_lead = re.compile('^\s+', re.MULTILINE)
          self.whitespace_trail = re.compile('\s+$', re.MULTILINE)
  
  
      def process_response(self, request, response):
          if "text" in response['Content-Type']:
              if hasattr(self, 'whitespace_lead'):
                  response.content = self.whitespace_lead.sub('', response.content)
              if hasattr(self, 'whitespace_trail'):
                  response.content = self.whitespace_trail.sub('\n', response.content)
              # Uncomment the next line to remove empty lines
              if hasattr(self, 'whitespace'):
                  response.content = self.whitespace.sub('', response.content)
              return response
          else:
              return response
  
subject: Create middleware.py