Remove unnecessary HTTP headers in my rails answers

后端 未结 3 1675
眼角桃花
眼角桃花 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:45

    You can do this with a piece of Rack middleware. See https://gist.github.com/02c1cc8ce504033d61bf for an example of to do it in one.

    When adding it to your app config, use something like config.middleware.insert_before(ActionDispatch::Static, ::HeaderDelete)

    You want to insert it before whatever the first item in the list that displays when you run rake middleware, which in my case is ActionDispatch::Static.

    http://guides.rubyonrails.org/rails_on_rack.html may be somewhat helpful if you haven't been exposed to Rack in the Rails context before.

提交回复
热议问题