Remove unnecessary HTTP headers in my rails answers

后端 未结 3 1688
眼角桃花
眼角桃花 2021-01-12 22:44

I am currently developing an API where size matters: I want the answer to contain as few bytes as possible. I optimized my JSON answer, but rails still responds with many st

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 23:22

    Another option, since you're using Nginx, is the HttpHeadersMoreModule. This will allow you to have fine-grain control of exactly which headers are sent down the wire.

    In your case, you'd specifically want to use the more_clear_headers directive, as such:

    more_clear_headers Server Date Status X-UA-Compatible Cache-Control X-Request-Id X-Runtime X-Rack-Cache;

    This also clears the Server header, since it's not really necessary, and if you're trying to save bytes, every little bit helps.

    This module does require you to compile Nginx on your own, but that really shouldn't scare you. Nginx is very easy to compile, just follow the installation instructions.

提交回复
热议问题