485969 - WebSocket upgrade response should honor HttpConfiguration server version settings

This commit is contained in:
Joakim Erdfelt 2016-01-15 13:23:06 -07:00
parent d41c0bba65
commit 9f8df9a1a8
2 changed files with 29 additions and 1 deletions

View File

@ -21,6 +21,8 @@ package org.eclipse.jetty.websocket.jsr356.server.browser;
import javax.servlet.ServletException;
import javax.websocket.DeploymentException;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.DefaultServlet;
@ -79,7 +81,11 @@ public class JsrBrowserDebugTool
private void setupServer(int port) throws DeploymentException, ServletException
{
server = new Server();
ServerConnector connector = new ServerConnector(server);
HttpConfiguration httpConf = new HttpConfiguration();
httpConf.setSendServerVersion(true);
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConf));
connector.setPort(port);
server.addConnector(connector);

View File

@ -36,11 +36,15 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.DecoratedObjectFactory;
@ -618,6 +622,9 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
if (LOG.isDebugEnabled())
LOG.debug("Handshake Response: {}", handshaker);
if (getSendServerVersion(connector))
response.setHeader("Server",HttpConfiguration.SERVER_VERSION);
// Process (version specific) handshake response
handshaker.doHandshakeResponse(request, response);
@ -626,4 +633,19 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
return true;
}
private boolean getSendServerVersion(Connector connector)
{
ConnectionFactory connFactory = connector.getConnectionFactory(HttpVersion.HTTP_1_1.asString());
if (connFactory == null)
return false;
if (connFactory instanceof HttpConnectionFactory)
{
HttpConfiguration httpConf = ((HttpConnectionFactory)connFactory).getHttpConfiguration();
if (httpConf != null)
return httpConf.getSendServerVersion();
}
return false;
}
}