Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the HTTP Server header in Jetty 9

Tags:

This is how you hide the server version in Jetty 8:

Server server = new Server(port); server.setSendServerVersion(false); 

How do you do it in Jetty 9? So now it should look something like this?

HttpConfiguration config = new HttpConfiguration(); config.setSendServerVersion(false); //TODO: Associate config with server??? Server server = new Server(port); 
like image 696
Jay Avatar asked Mar 27 '13 06:03

Jay


2 Answers

In Jetty 9, you need to configure it on HttpConfiguration:

HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSendServerVersion( false ); HttpConnectionFactory httpFactory = new HttpConnectionFactory( httpConfig ); ServerConnector httpConnector = new ServerConnector( server,httpFactory ); server.setConnectors( new Connector[] { httpConnector } ); 
like image 61
djschny Avatar answered Sep 18 '22 06:09

djschny


If worked out some code that seems to work. Not sure if its right, but at least it works (:

Server server = new Server(port); for(Connector y : server.getConnectors()) {     for(ConnectionFactory x  : y.getConnectionFactories()) {         if(x instanceof HttpConnectionFactory) {             ((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(false);         }     } } 
like image 44
Jay Avatar answered Sep 20 '22 06:09

Jay