Skip to content Skip to sidebar Skip to footer

Get All "accept" Headers From Flask

A client sends multiple Accept headers to my Flask app. However, request.headers('accept') return only the last set header. How can I see all values for the Accept header so that I

Solution 1:

request.headers is a MultiDict, which provides the getlist method to get all the values for a given key.

request.headers.getlist('accept')

The default Request class parses accept headers into more useful forms. Since you specifically care about the accept headers, use these attributes instead.

if request.accept_mimetypes.accept_json:
    ...

Post a Comment for "Get All "accept" Headers From Flask"