How to get http headers in flask?

emil picture emil · Apr 1, 2015 · Viewed 168.2k times · Source

I am newbie to python and using Python Flask and generating REST API service.

I want to check authorization header which is sent the client.

But I can't find way to get HTTP header in flask.

Any help for getting HTTP header authorization is appreciated.

Answer

sanyi picture sanyi · Apr 1, 2015
from flask import request
request.headers.get('your-header-name')

request.headers behaves like a dictionary, so you can also get your header like you would with any dictionary:

request.headers['your-header-name']