我想洗掉一些我的網路服務器注入到標頭回應中但無法洗掉的標頭
我只看到添加標題的輔助函式,但無法在 Grape 中洗掉它們,而且我似乎找不到包含標題的變數
我特別想洗掉X-Powered-By由我的乘客服務器注入的內容,乘客似乎只提供洗掉版本號的能力,但不能完全洗掉它......這似乎不安全......
我想在我的before街區做這個
before do
## I see i can easily add headers, but not remove
header 'X-Robots-Tag', 'noindex'
## how do I remove headers here?
## ...
end
## ... some routes
get '/' do
## ...
end
許多庫提供洗掉標頭的功能,例如:
ExpressJS
app.use(function (req, res, next) {
res.header('Pragma', 'no-cache');
res.removeHeader('Pragma');
next();
});
導軌
response.headers['Connection'] = 'Closed'
remove_keys = %w(X-Runtime Cache-Control Server Etag Set-Cookie)
response.headers.delete_if{|key| remove_keys.include? key}
uj5u.com熱心網友回復:
雖然在我看來有點尷尬,但檔案確實表明您可以通過僅傳遞鍵而不是值(或將值傳遞為nil)來洗掉標題
對于您的示例:
before do
## I see i can easily add headers, but not remove
header 'X-Robots-Tag', 'noindex'
## how do I remove headers here?
header 'X-Powered-By'
end
我猜這個概念是設定為非值的標頭根本不是真正的標頭。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/491513.html
