title: How to access Flask Request header outside route method
body: <p>I want to access headers for a certain API calls outside of its api route. I tried using the app_context and test_request_context but it doesn't seem to work.</p>
  <pre><code>from flask import Flask, request
  
  app = Flask(&quot;app&quot;)
  
  def access_header_for_something():
      with app.test_request_context():
          with app.app_context():
              print(request.headers.get(&quot;Authorization&quot;), request.host, request.path)
  
  
  @app.route('/')
  def index():
      access_header_for_something()
      return 'hello'
  
  if __name__==&quot;__main__&quot;:
      app.run(debug=True)
  </code></pre>
  <p>Any suggestions would be really helpful</p>