这是你如何藏在码头8的服务器版本中删除HTTP Server头?那么现在应该看起来像这样?在码头9
HttpConfiguration config = new HttpConfiguration();
config.setSendServerVersion(false);
//TODO: Associate config with server???
Server server = new Server(port);
这是你如何藏在码头8的服务器版本中删除HTTP Server头?那么现在应该看起来像这样?在码头9
HttpConfiguration config = new HttpConfiguration();
config.setSendServerVersion(false);
//TODO: Associate config with server???
Server server = new Server(port);
如果制定了一些代码,似乎工作。不知道其权利,但至少它的工作原理(:
Server server = new Server(port);
for(Connector y : server.getConnectors()) {
for(ConnectionFactory x : y.getConnectionFactories()) {
if(x instanceof HttpConnectionFactory) {
((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(false);
}
}
}
现在有一个HttpConfiguration对象,它的设置。
org.eclipse.jetty.server.HttpConfiguration
查找到的jetty.xml有关HTTP配置部分的部分示出了如何设置对象,然后码头-http.xml文件,其显示了如何该配置用来。请记住,jetty xml文件实际上只是一个超薄的Java皮肤,并且工作原理基本相同。
在码头9,你需要在HttpConfiguration配置它:
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSendServerVersion(false);
HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
ServerConnector httpConnector = new ServerConnector(server,httpFactory);
server.setConnectors(new Connector[] { httpConnector });
您应该添加最后一步:'server.setConnectors(new Connector [] {httpConnector});'。 – 2014-07-26 13:50:53
为新连接器设置端口的重要位是:'httpConnector.setPort(port);'。由于默认连接器正在被替换,因此不会使用传递给“服务器”构造函数的端口。 – Ben 2016-10-06 15:34:11
一些安全分析软件将标志向服务器发送版本响应报头作为一个问题。
OP一直在寻找解决方案,嵌入式,但如果你的码头部署使用server.ini文件,你可以简单地设置jetty.send.server.version =假
如果您使用jetty9作为独立服务器,则可以通过在文件start.ini
中设置jetty.httpConfig.sendServerVersion=false
来禁用服务器签名。
雅各布的解决方案(这为我工作)的λ-风格的变体:
final Server server = new Server(port);
Stream.of(server.getConnectors()).flatMap(connector -> connector.getConnectionFactories().stream())
.filter(connFactory -> connFactory instanceof HttpConnectionFactory)
.forEach(httpConnFactory -> ((HttpConnectionFactory)httpConnFactory).getHttpConfiguration().setSendServerVersion(false));
jetty9.2
,在start.ini
# should jetty send the server version header?
jetty.send.server.version=true
我知道禁止向服务器发送版本更改此配置,以
false
不理想的,但我有一个特定的场景,现在我无法避免它。 – Jacob 2013-03-27 23:26:55为什么_sending服务器版本不理想_?我的意思是没有客户应该使用它,它可能有安全隐患。在我看来,它应该被禁用默认或我错过了什么? – 2015-07-28 14:32:55
服务器标题是绝对使用的,它可能会影响您的搜索排名,也可用于创建技术/浏览器流行度图表,这些图表经常被某些类型的人员用于制定技术决策。 – Jacob 2015-07-29 09:22:03