title: How to change response and content-length in uwsgi middleware?
body: <p>I'm trying to write a middleware which replaces some data in the response thus changing the content length. For our development environment we want to simulate the behaviour of SSI includes of the actual webserver like Nginx or Apache for some static files which are not served through the application. We're using the included development server of werkzeug.</p>
  
  <p>Here is what i have so far:</p>
  
  <pre><code>class ModifyBodyMiddleware(object):
      def __init__(self, app):
          self.app = app
  
      def __call__(self, environment, start_response):
          def my_start_response(status, headers, exc_info=None):
              # change content-length somehow
              start_response(status, headers, exc_info)
  
          body = self.app(environment, my_start_response)
          body = do_modifications(body)
  
          return body
  </code></pre>
  
  <p>For simplification just assume <code>do_modifications</code> does replace the whole content with <code>foobar</code>. I need the actual body to modify it but i also need to set the new content-length header somehow.</p>
  
  <p>Thanks
  Goir</p>