Skip to content
Advertisement

Print raw HTTP request in Flask or WSGI

I am debugging a microcontroller I’ve built which is writing raw HTTP requests line by line. I am using Flask for my backend and I would like to see the entire request as it appears in this format:

GET / HTTP/1.1
Content-length: 123
User-agent: blah
...

I know Flask is based on WSGI. Is there anyway to get this to work with Flask?

Advertisement

Answer

With flask you have access to the request object which contains all the HTTP details:

from flask import request

@app.route('/')
def index():
    print(request.headers)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement