title: How to access request in Flask Middleware
body: <p>I want to access request.url in middleware.</p>
  
  <p>Flask app - test.py</p>
  
  <pre><code>from flask import Flask
  from middleware import TestMiddleware
  app = Flask(__name__)
  
  app.wsgi_app = TestMiddleware(app.wsgi_app)
  
  @app.route('/')
  def hello_world():
      return 'Hello World!'
  
  if __name__ == '__main__':
      app.run()
  </code></pre>
  
  <p>middleware.py:</p>
  
  <pre><code>from flask import request
  
  class TestMiddleware(object):
  
      def __init__(self, app):
          self.app = app 
  
      def __call__(self, environ, start_response):
          # How do I access request object here.
          print "I'm in middleware"
          return self.app(environ, start_response)
  </code></pre>
  
  <p>I understand request can be accessed in Flask application context. We normally use </p>
  
  <pre><code>with app.test_request_context()
  </code></pre>
  
  <p>But in middleware, I don't have access to Flask app object.</p>
  
  <p>How do I proceed?</p>
  
  <p>Thanks for any help..</p>