1

I've developed a web application in Ruby (using Sinatra framework if that matters).

It adds a Server header to every HTTP response:

Server: WEBrick/1.3.1 (Ruby/1.9.3/2011-09-23)

How do I disable it?

Oleg Mikheev
  • 17,186
  • 14
  • 73
  • 95
  • Unrelated to the direct core of the question but it should be noted nevertheless: You should not use webrick for production hosting (unless you have a very good reason to do that, if you have to ask which, you don't) You should use something like Passenger, Thin or Unicorn instead. They are all faster, scale better (or at all) and are much better administerable. – Holger Just Nov 26 '11 at 21:39
  • yes I know, but I'm developing just a simple personal blog just for fun, so I don't care much about performance... I just don't feel comfortable revealing its lame nature to the public :) I will consider switching to Passenger on production, especially if I ever get an answer to [this question](http://serverfault.com/questions/334812/can-i-compile-passenger-mod-rails-mod-rack-to-make-a-statically-linked-apache/335018#335018) – Oleg Mikheev Nov 26 '11 at 21:57

1 Answers1

0

I'm not sure that you can delete Server header at all without hacking the guts. I think that more simple is delete all content of this header such way:

require 'sinatra'

set :server, 'WEBrick'

get '/' do
  headers "Server" => ""
  "Hello, World!"
end

If you want to prepare this manipulation for each action, you can use before filter:

require 'sinatra'

set :server, 'WEBrick'

before do
  headers "Server" => ""
end

get '/' do
  "Hello, World!"
end
WarHog
  • 8,622
  • 2
  • 29
  • 23
  • Actually your code results in no `Server` header at all - that's great! But there must be some way not to put this extra line to ALL methods that I implement? – Oleg Mikheev Nov 26 '11 at 22:13
  • I've updated my post. But i'm wondering, how do you check presence of `Server` header? Because yeah - firebug doesn't show empty header, but if you look at chrome, you can discover it among other header with. – WarHog Nov 26 '11 at 22:24
  • I'm using Live HTTP headers Firefox extension and was thinking that it was a great tool, until now... might be a Firefox issue – Oleg Mikheev Nov 26 '11 at 22:29