2017-01-27 9 views
0

プラットフォーム:node.js + expressおよびrequest modules(beginner)。node.js - レスポンスヘッダーを変更する方法

こんにちは、単純にrouter.getの後にリクエストがあり、外部サーバーから取得したヘッダーを変更して、特定のデータを要求したユーザーに送信します。

router.get('/', function(req, res){ 
    var someUserRequest = request('http://google.com', function(error, resp, body){ 
     if (error){ 
     console.log(error); 
     } 
     console.log(resp.headers); //lets assume that there is 'x-content-type-options' that I don't want for example 
    } 
    req.pipe(someUserRequest).on('response', function(response){ 
    delete response.headers['x-content-type-options']; 
    console.log(response.headers); // everything looks fine here - no 'x-content-type-options' 
    }).pipe(res); 
}); 
module.exports = router; 

したがって、 'x-content-type-options'はありません。しかし、これをクロム開発ツール(ネットワーク)でチェックすると、すべての履歴/キャッシュをクリアしても、「x-content-type-options:nosniff」がはっきりと確認できます。

なぜ機能しないのですか?誰かがエラーがどこにあるのか教えていただけますか?

答えて

1

は、私はあなたが

['x-content-type-options'] 

がresponse.headersに存在する場合、あなた

delete 

を見るために、代わりに配列をスプライスする前と後のテスト条件を入れてみてくださいする必要があるかもしれないと思います。

もしそうであれば、おそらく代わりにスプライスすることができます。

続きを読むdeleteここに

関連する問題