Skip to content

Commit

Permalink
Issue #4765 - Review GzipHandler inside ServletContextHandler.
Browse files Browse the repository at this point in the history
Removed GzipHandler from ServletContextHandler.
Updated ServletContextHandlerTest.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Apr 13, 2020
1 parent 93774ae commit 1a234dc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public class ServletContextHandler extends ContextHandler

public static final int SESSIONS = 1;
public static final int SECURITY = 2;
public static final int GZIP = 4;
public static final int NO_SESSIONS = 0;
public static final int NO_SECURITY = 0;

Expand Down Expand Up @@ -128,7 +127,6 @@ public interface ServletContainerInitializerCaller extends LifeCycle {}
protected SessionHandler _sessionHandler;
protected SecurityHandler _securityHandler;
protected ServletHandler _servletHandler;
protected GzipHandler _gzipHandler;
protected int _options;
protected JspConfigDescriptor _jspConfig;

Expand Down Expand Up @@ -281,21 +279,6 @@ private void relinkHandlers()
handler = _securityHandler;
}

// link gzip handler
if (getGzipHandler() != null)
{
while (!(handler.getHandler() instanceof GzipHandler) &&
!(handler.getHandler() instanceof ServletHandler) &&
handler.getHandler() instanceof HandlerWrapper)
{
handler = (HandlerWrapper)handler.getHandler();
}

if (handler.getHandler() != _gzipHandler)
doSetHandler(handler, _gzipHandler);
handler = _gzipHandler;
}

// link servlet handler
if (getServletHandler() != null)
{
Expand Down Expand Up @@ -369,8 +352,6 @@ protected ServletHandler newServletHandler()

/**
* Finish constructing handlers and link them together.
*
* @see org.eclipse.jetty.server.handler.ContextHandler#startContext()
*/
@Override
protected void startContext() throws Exception
Expand Down Expand Up @@ -440,17 +421,6 @@ public SessionHandler getSessionHandler()
return _sessionHandler;
}

/**
* @return Returns the gzipHandler.
*/
@ManagedAttribute(value = "context gzip handler", readonly = true)
public GzipHandler getGzipHandler()
{
if (_gzipHandler == null && (_options & GZIP) != 0 && !isStarted())
_gzipHandler = new GzipHandler();
return _gzipHandler;
}

/**
* Convenience method to add a servlet.
*
Expand Down Expand Up @@ -652,16 +622,6 @@ public void setSecurityHandler(SecurityHandler securityHandler)
relinkHandlers();
}

/**
* @param gzipHandler The {@link GzipHandler} to set on this context.
*/
public void setGzipHandler(GzipHandler gzipHandler)
{
replaceHandler(_gzipHandler, gzipHandler);
_gzipHandler = gzipHandler;
relinkHandlers();
}

/**
* @param servletHandler The servletHandler to set.
*/
Expand All @@ -683,8 +643,6 @@ public void insertHandler(HandlerWrapper handler)
setSessionHandler((SessionHandler)handler);
else if (handler instanceof SecurityHandler)
setSecurityHandler((SecurityHandler)handler);
else if (handler instanceof GzipHandler)
setGzipHandler((GzipHandler)handler);
else if (handler instanceof ServletHandler)
setServletHandler((ServletHandler)handler);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.Decorator;
Expand Down Expand Up @@ -1630,30 +1629,6 @@ public void testHandlerBeforeServletHandler() throws Exception
assertEquals(extra, context.getSessionHandler().getHandler());
}

@Test
public void testGzipHandlerOption() throws Exception
{
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.GZIP);
GzipHandler gzip = context.getGzipHandler();
_server.start();
assertEquals(context.getSessionHandler(), context.getHandler());
assertEquals(gzip, context.getSessionHandler().getHandler());
assertEquals(context.getServletHandler(), gzip.getHandler());
}

@Test
public void testGzipHandlerSet() throws Exception
{
ServletContextHandler context = new ServletContextHandler();
context.setSessionHandler(new SessionHandler());
context.setGzipHandler(new GzipHandler());
GzipHandler gzip = context.getGzipHandler();
_server.start();
assertEquals(context.getSessionHandler(), context.getHandler());
assertEquals(gzip, context.getSessionHandler().getHandler());
assertEquals(context.getServletHandler(), gzip.getHandler());
}

@Test
public void testReplaceServletHandlerWithServlet() throws Exception
{
Expand Down Expand Up @@ -1689,24 +1664,19 @@ public void testReplaceServletHandlerWithServlet() throws Exception
@Test
public void testSetSecurityHandler() throws Exception
{
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY | ServletContextHandler.GZIP);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY);
assertNotNull(context.getSessionHandler());
SessionHandler sessionHandler = context.getSessionHandler();
assertNotNull(context.getSecurityHandler());
SecurityHandler securityHandler = context.getSecurityHandler();
assertNotNull(context.getGzipHandler());
GzipHandler gzipHandler = context.getGzipHandler();


//check the handler linking order
HandlerWrapper h = (HandlerWrapper)context.getHandler();
assertSame(h, sessionHandler);

h = (HandlerWrapper)h.getHandler();
assertSame(h, securityHandler);

h = (HandlerWrapper)h.getHandler();
assertSame(h, gzipHandler);

//replace the security handler
SecurityHandler myHandler = new SecurityHandler()
{
Expand Down Expand Up @@ -1747,9 +1717,6 @@ protected boolean checkWebResourcePermissions(String pathInContext, Request requ

h = (HandlerWrapper)h.getHandler();
assertSame(h, myHandler);

h = (HandlerWrapper)h.getHandler();
assertSame(h, gzipHandler);
}

@Test
Expand Down

0 comments on commit 1a234dc

Please sign in to comment.