How to prevent Gunicorn from returning a 'Server' http header?

后端 未结 6 1110
走了就别回头了
走了就别回头了 2021-02-05 06:51

I would like to mask the version or remove the header altogether.

6条回答
  •  故里飘歌
    2021-02-05 07:34

    My mocky-patch free solution, involves wrapping the default_headers method:

    import gunicorn.http.wsgi
    from six import wraps
    
    
    def wrap_default_headers(func):
        @wraps(func)
        def default_headers(*args, **kwargs):
            return [header for header in func(*args, **kwargs) if not header.startswith('Server: ')]
        return default_headers
    
    
    gunicorn.http.wsgi.Response.default_headers = wrap_default_headers(gunicorn.http.wsgi.Response.default_headers)
    

提交回复
热议问题