2

I am trying to develop a web service back-end for an Alexa skill, and this requires me to have very specific headers in the HTTP response.

Looking at the details of my response (using hurl.it), I have a whole bunch of HTTP headers that Amazon doesn't want. How can I remove the 'X-Clacks-Overhead', the 'Server', etc., responses.

I am using Flask and Python 3.

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
user1403142
  • 81
  • 1
  • 7

2 Answers2

4

If your header is actually being set by Flask, you can remove it from the headers dict on the response by using Flask's after_request function/decorator:

@app.after_request
def remove_header(response):
    del response.headers['X-Some-Custom-Header']

    return response

With the likes of Server, it's likely this is being set by an upstream provider and not Flask directly, so you'd need to remove it from whatever is proxying the request from Flask and outputting to the user.

Lee Benson
  • 11,185
  • 6
  • 43
  • 57
2

You can't, but I seriously doubt that anyone would write code that would fall down when there were extra headers fields in a request. Perhaps you're misinterpreting the error.

Glenn
  • 7,262
  • 1
  • 17
  • 23
  • Glenn: you are absolutely correct. My problem was malformed JSON, and I was getting a misleading error message – user1403142 May 01 '16 at 22:20
  • The answer to the would-be question can be found here: https://stackoverflow.com/questions/30717152/python-flask-how-to-set-response-header-for-all-responses – 657784512 May 28 '17 at 18:24