Forums

Double X-Clacks-Overhead

I have recently migrated my flask app into PythonAnywhere. As a responsible web admin I add the HTTP header X-Clacks-Overhead: GNU Terry Pratchett. That was fine with my previous host but PythonAnywhere adds that header too. So my web pages are served up with two copies of that header. The static pages correctly have one.

I tried to mitigate the issue with this bit of code. OpenResty presumably adds its headers after mine.

@app.after_request
def gnu_terry_pratchett(resp):
    if not resp.headers.has_key('X-Clacks-Overhead'):
        resp.headers.add('X-Clacks-Overhead', 'GNU Terry Pratchett')
    return resp

Would it be possible to configure OpenResty to do the same thing? If not I will just change my if condition to some sort of is_python_anywhere().

hi there, we'll look into it, but we might not be able to get it done quickly, so in the short term an is_python_anywhere might work... one way to do that would be to look for the string "liveweb" in the machine hostname?

A short term fix is fine. Thanks for the response.

@app.after_request
def gnu_terry_pratchett(resp):
    if request.environ.get('SERVER_NAME') != 'payg.pythonanywhere.com':
        # PythonAnywhere already has this header
        resp.headers.add('X-Clacks-Overhead', 'GNU Terry Pratchett')
    return resp