Sinatra on Thin: how to hide or change the HTTP Server response header

What is the cleanest way to do this? Some middleware middleware? I tried to change env['SERVER_SOFTWARE'], but I still get in response:

Server: thin 1.3.1 codename Triple Espresso

How to change the value of this header or completely remove it from the response?

EDIT

Another attempt:

before do
  headers 'Server' => 'ipm'
end

after do
  headers 'Server' => 'ipm'
end

But there were no changes.

+3
source share
1 answer

This works here:

require 'sinatra'

get '/' do
  [200, {'Server' => 'My Server'}, 'contents']
end

If you want to do this for all queries:

class ChangeServer
  def initialize(app)
    @app = app
  end

  def call(env)
    res = @app.call(env)
    res[1]['Server'] = 'My server'
    return res
  end
end

And then you are use ChangeServerin your application.

+4
source

All Articles