prevent /status from redirect, fixes #953

This commit is contained in:
Xavier Léauté 2014-12-10 11:32:22 -08:00
parent 3055a562ab
commit 5f3f4e0a60
3 changed files with 12 additions and 85 deletions

View File

@ -1,80 +0,0 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.server.http;
import com.google.inject.Inject;
import com.metamx.common.logger.Logger;
import org.eclipse.jetty.servlet.DefaultServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
/**
*/
public class RedirectServlet extends DefaultServlet
{
private static final Logger log = new Logger(RedirectServlet.class);
private final RedirectInfo redirectInfo;
@Inject
public RedirectServlet(
RedirectInfo redirectInfo
)
{
this.redirectInfo = redirectInfo;
}
@Override
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException
{
HttpServletRequest request;
HttpServletResponse response;
try {
request = (HttpServletRequest) req;
response = (HttpServletResponse) res;
}
catch (ClassCastException e) {
throw new ServletException("non-HTTP request or response");
}
if (redirectInfo.doLocal()) {
super.service(request, response);
} else {
final URL redirectURL = redirectInfo.getRedirectURL(request.getQueryString(), request.getRequestURI());
if (redirectURL == null) {
response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
}
else {
log.info("Forwarding request to [%s]", redirectURL);
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location", redirectURL.toString());
}
}
}
}

View File

@ -239,11 +239,15 @@ public class CliOverlord extends ServerRunnable
}
)
);
root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null);
root.addFilter(GzipFilter.class, "/*", null);
// Can't use /* here because of Guice and Jetty static content conflicts
// /status should not redirect, so add first
root.addFilter(GuiceFilter.class, "/status/*", null);
// redirect anything other than status to the current lead
root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null);
// Can't use /* here because of Guice and Jetty static content conflicts
root.addFilter(GuiceFilter.class, "/druid/*", null);
HandlerList handlerList = new HandlerList();

View File

@ -60,13 +60,16 @@ class CoordinatorJettyServerInitializer implements JettyServerInitializer
} else {
root.setResourceBase(config.getConsoleStatic());
}
root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null);
root.addFilter(GzipFilter.class, "/*", null);
// /status should not redirect, so add first
root.addFilter(GuiceFilter.class, "/status/*", null);
// redirect anything other than status to the current lead
root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null);
// Can't use '/*' here because of Guice and Jetty static content conflicts
// The coordinator really needs a standarized api path
root.addFilter(GuiceFilter.class, "/status/*", null);
root.addFilter(GuiceFilter.class, "/info/*", null);
root.addFilter(GuiceFilter.class, "/druid/coordinator/*", null);
// this will be removed in the next major release