简体   繁体   English

如何禁用WEBrick服务器头

[英]how to disable WEBrick Server header

I've developed a web application in Ruby (using Sinatra framework if that matters). 我已经在Ruby中开发了一个Web应用程序(如果需要的话,可以使用Sinatra框架)。

It adds a Server header to every HTTP response: 它将Server标头添加到每个HTTP响应:

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

How do I disable it? 如何禁用它?

I'm not sure that you can delete Server header at all without hacking the guts. 我不确定您是否可以完全删除Server标头而不破坏其胆量。 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: 如果要为每个操作准备此操作,则可以before过滤器before使用:

require 'sinatra'

set :server, 'WEBrick'

before do
  headers "Server" => ""
end

get '/' do
  "Hello, World!"
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM