バージョンをマスクするか、ヘッダーを完全に削除したいと思います。
9159 次
7 に答える
28
「Server:」http ヘッダーを変更するには、conf.py ファイルで次のようにします。
import gunicorn
gunicorn.SERVER_SOFTWARE = 'Microsoft-IIS/6.0'
そして、次の行に沿って呼び出しを使用しますgunicorn -c conf.py wsgi:app
ヘッダーを完全に削除するには、gunicorn の http 応答クラスを、ヘッダーを除外するサブクラスに置き換えることでモンキー パッチを適用できます。これは無害かもしれませんが、おそらく推奨されません。conf.py に次のように記述します。
from gunicorn.http import wsgi
class Response(wsgi.Response):
def default_headers(self, *args, **kwargs):
headers = super(Response, self).default_headers(*args, **kwargs)
return [h for h in headers if not h.startswith('Server:')]
wsgi.Response = Response
ガンコーン18でテスト済み
于 2014-01-22T21:37:56.473 に答える
1
私のモックパッチ無料のソリューションには、default_headers メソッドをラップすることが含まれます。
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)
于 2018-07-24T18:14:20.770 に答える