a flask app that listens to port 80 and prints all the headers in python

Here is how to create a Flask app that listens to port 80 and prints all headers in Python:

main.py
from flask import Flask, request

app = Flask(__name__)

@app.before_request
def log_request():
    print(request.headers)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80)
188 chars
11 lines

In the code above, we have created a Flask app and a before_request decorator that prints all the headers of the incoming requests. We have also set the host to 0.0.0.0 and port to 80, which means the app will listen to all incoming requests on port 80.

You can run this app simply by saving the above code in a file named app.py and running python app.py. Keep in mind that running an app as a superuser on port 80 could be unsafe, so it is not recommended to deploy your application with this configuration on a production server.

related categories

gistlibby LogSnag