B4J Question Possible to remove the HTTP Server header version in Jetty ?

Luk

Member
Licensed User
Longtime User
Hi,

Is it possible to remove the HTTP Server header version in Jetty ? Why ?
Some security analysis software (and colleagues :)) will flag sending the server version in the response header as an issue.

This java code should do it, but I don't know how this can be done in B4J
B4X:
HttpConfiguration httpConfig =newHttpConfiguration();
httpConfig.setSendServerVersion(false);
HttpConnectionFactory httpFactory =newHttpConnectionFactory( httpConfig );
ServerConnector httpConnector =newServerConnector( server,httpFactory );

Thanks.
Luk
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Call this sub after the server is started:
B4X:
Private Sub RemoveServerVersionFromResponses (Server As Server)
   Dim jo As JavaObject = Server
   jo = jo.GetField("server")
   Dim connectors() As Object = jo.RunMethod("getConnectors", Null)
   For Each co As JavaObject In connectors
     Dim connections() As Object = co.RunMethodJO("getConnectionFactories", Null).RunMethod("toArray", Null)
     For Each connection As JavaObject In connections
       If GetType(connection) = "org.eclipse.jetty.server.HttpConnectionFactory" Then
         Dim configuration As JavaObject = connection.RunMethod("getHttpConfiguration", Null)
         configuration.RunMethod("setSendServerVersion", Array(False))
       End If
     Next
   Next
End Sub
 
Last edited:
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
B4X:
' should be something like

Private Sub RemoveServerVersionFromResponses (Server1 As Server)
       Dim jo AsJavaObject = Server1
       ...
 
Upvote 0
Top