I can see my custom headers with connexion.request.headers['X-MyHeader'] when I place it directly in my app.py (shown below) in the def home() function, but I could not find a way to pass them to my endpoint "users" which is on a separate file and is referenced through the swagger.yml file's operationId: "users.getUsers".
I have been looking for a way to pass the value of connexion.request.headers['X-MyHeader'] to my users.getUsers function but no luck so far. This one seemed close enough https://github.com/zalando/connexion/issues/1210 but looks like it is for aiohttp, while I am currently testing on Flask.
# Create a URL route in our application for "/"
@app.route('/')
def home():
"""
This function just responds to the browser ULR
localhost:5000/
:return: the rendered template 'home.html'
"""
print(connexion.request.headers['X-MyHeader'])
return render_template('home.html')
app.run(host='0.0.0.0', port=5000, debug=True)`
Description
I can see my custom headers with
connexion.request.headers['X-MyHeader']
when I place it directly in my app.py (shown below) in the def home() function, but I could not find a way to pass them to my endpoint "users" which is on a separate file and is referenced through the swagger.yml file's operationId: "users.getUsers".I have been looking for a way to pass the value of connexion.request.headers['X-MyHeader'] to my users.getUsers function but no luck so far. This one seemed close enough https://github.com/zalando/connexion/issues/1210 but looks like it is for aiohttp, while I am currently testing on Flask.
app.py
`from flask import render_template import connexion
class ReverseProxied(object): ''' https://github.com/zalando/connexion/blob/master/examples/openapi3/reverseproxy/app.py '''
if name == 'main': app = connexion.FlaskApp(name, specification_dir='./swagger/') app.add_api('swagger.yml') flask_app = app.app proxied = ReverseProxied( flask_app.wsgi_app, script_name='/api/' ) flask_app.wsgi_app = proxied
Output of the commands: