Skip to content

Commit

Permalink
ARTEMIS-1826 don't send 'Server' HTTP header
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram authored and clebertsuconic committed Apr 26, 2018
1 parent 27c0017 commit e8a88c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Expand Up @@ -31,6 +31,7 @@
import org.apache.activemq.artemis.dto.WebServerDTO;
import org.apache.activemq.artemis.utils.FileUtil;
import org.apache.activemq.artemis.utils.TimeUtils;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
Expand Down Expand Up @@ -81,12 +82,16 @@ public void configure(ComponentDTO config, String artemisInstance, String artemi

HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
https.setSendServerVersion(false);
HttpConnectionFactory httpFactory = new HttpConnectionFactory(https);

connector = new ServerConnector(server, sslConnectionFactory, httpFactory);

} else {
connector = new ServerConnector(server);
HttpConfiguration configuration = new HttpConfiguration();
configuration.setSendServerVersion(false);
ConnectionFactory connectionFactory = new HttpConnectionFactory(configuration);
connector = new ServerConnector(server, connectionFactory);
}
connector.setPort(uri.getPort());
connector.setHost(uri.getHost());
Expand Down
Expand Up @@ -41,6 +41,7 @@
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.ssl.SslHandler;
import io.netty.util.CharsetUtil;
Expand Down Expand Up @@ -110,6 +111,7 @@ protected void initChannel(Channel ch) throws Exception {
ch.writeAndFlush(request);
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(clientHandler.body, "12345");
assertNull(clientHandler.serverHeader);
// Wait for the server to close the connection.
ch.close();
Assert.assertTrue(webServerComponent.isStarted());
Expand Down Expand Up @@ -205,6 +207,7 @@ protected void initChannel(Channel ch) throws Exception {
ch.writeAndFlush(request);
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(clientHandler.body, "12345");
assertNull(clientHandler.serverHeader);
// Wait for the server to close the connection.
ch.close();
Assert.assertTrue(webServerComponent.isStarted());
Expand Down Expand Up @@ -309,14 +312,18 @@ class ClientHandler extends SimpleChannelInboundHandler<HttpObject> {

private CountDownLatch latch;
private String body;
private String serverHeader;

ClientHandler(CountDownLatch latch) {
this.latch = latch;
}

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
if (msg instanceof HttpContent) {
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;
serverHeader = response.headers().get("Server");
} else if (msg instanceof HttpContent) {
HttpContent content = (HttpContent) msg;
body = content.content().toString(CharsetUtil.UTF_8);
latch.countDown();
Expand Down

0 comments on commit e8a88c4

Please sign in to comment.