mirror of https://github.com/apache/lucene.git
SOLR-7547: Short circuit SolrDispatchFilter for static content request. Right now it creates a new HttpSolrCall object and tries to process it.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1679493 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fba2134157
commit
d0251d9b10
|
@ -270,6 +270,9 @@ Optimizations
|
||||||
* SOLR-7324: IndexFetcher does not need to call isIndexStale if full copy is already needed
|
* SOLR-7324: IndexFetcher does not need to call isIndexStale if full copy is already needed
|
||||||
(Stephan Lagraulet via Varun Thacker)
|
(Stephan Lagraulet via Varun Thacker)
|
||||||
|
|
||||||
|
* SOLR-7547: Short circuit SolrDisptachFilter for static content request. Right now it creates
|
||||||
|
a new HttpSolrCall object and tries to process it. (Anshum Gupta)
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -400,13 +400,7 @@ public class HttpSolrCall {
|
||||||
1. Authorization is enabled, and
|
1. Authorization is enabled, and
|
||||||
2. The requested resource is not a known static file
|
2. The requested resource is not a known static file
|
||||||
*/
|
*/
|
||||||
// TODO: There should be a better way to ignore the static files.
|
if (cores.getAuthorizationPlugin() != null) {
|
||||||
if (cores.getAuthorizationPlugin() != null &&
|
|
||||||
!(req.getRequestURI().endsWith(".html")
|
|
||||||
|| req.getRequestURI().endsWith(".png")
|
|
||||||
|| req.getRequestURI().endsWith(".ico")
|
|
||||||
|| req.getRequestURI().endsWith(".css")
|
|
||||||
)) {
|
|
||||||
AuthorizationContext context = getAuthCtx();
|
AuthorizationContext context = getAuthCtx();
|
||||||
log.info(context.toString());
|
log.info(context.toString());
|
||||||
AuthorizationResponse authResponse = cores.getAuthorizationPlugin().authorize(context);
|
AuthorizationResponse authResponse = cores.getAuthorizationPlugin().authorize(context);
|
||||||
|
|
|
@ -17,10 +17,6 @@
|
||||||
|
|
||||||
package org.apache.solr.servlet;
|
package org.apache.solr.servlet;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
import javax.servlet.FilterConfig;
|
import javax.servlet.FilterConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -28,6 +24,12 @@ import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -57,6 +59,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {
|
||||||
|
|
||||||
protected String abortErrorMessage = null;
|
protected String abortErrorMessage = null;
|
||||||
protected final CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
|
protected final CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
|
||||||
|
private ArrayList<Pattern> excludePatterns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum to define action that needs to be processed.
|
* Enum to define action that needs to be processed.
|
||||||
|
@ -81,7 +84,14 @@ public class SolrDispatchFilter extends BaseSolrFilter {
|
||||||
public void init(FilterConfig config) throws ServletException
|
public void init(FilterConfig config) throws ServletException
|
||||||
{
|
{
|
||||||
log.info("SolrDispatchFilter.init()" + this.getClass().getClassLoader());
|
log.info("SolrDispatchFilter.init()" + this.getClass().getClassLoader());
|
||||||
|
String exclude = config.getInitParameter("excludePatterns");
|
||||||
|
if(exclude != null) {
|
||||||
|
String[] excludeArray = exclude.split(",");
|
||||||
|
excludePatterns = new ArrayList();
|
||||||
|
for (String element : excludeArray) {
|
||||||
|
excludePatterns.add(Pattern.compile(element));
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Properties extraProperties = (Properties) config.getServletContext().getAttribute(PROPERTIES_ATTRIBUTE);
|
Properties extraProperties = (Properties) config.getServletContext().getAttribute(PROPERTIES_ATTRIBUTE);
|
||||||
if (extraProperties == null)
|
if (extraProperties == null)
|
||||||
|
@ -170,6 +180,19 @@ public class SolrDispatchFilter extends BaseSolrFilter {
|
||||||
|
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throws IOException, ServletException {
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throws IOException, ServletException {
|
||||||
if (!(request instanceof HttpServletRequest)) return;
|
if (!(request instanceof HttpServletRequest)) return;
|
||||||
|
|
||||||
|
// No need to even create the HttpSolrCall object if this path is excluded.
|
||||||
|
if(excludePatterns != null) {
|
||||||
|
String servletPath = ((HttpServletRequest) request).getServletPath().toString();
|
||||||
|
for (Pattern p : excludePatterns) {
|
||||||
|
Matcher matcher = p.matcher(servletPath);
|
||||||
|
if (matcher.lookingAt()) {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HttpSolrCall call = new HttpSolrCall(this, cores, (HttpServletRequest) request, (HttpServletResponse) response, retry);
|
HttpSolrCall call = new HttpSolrCall(this, cores, (HttpServletRequest) request, (HttpServletResponse) response, retry);
|
||||||
try {
|
try {
|
||||||
Action result = call.call();
|
Action result = call.call();
|
||||||
|
|
|
@ -49,27 +49,15 @@
|
||||||
<filter>
|
<filter>
|
||||||
<filter-name>SolrRequestFilter</filter-name>
|
<filter-name>SolrRequestFilter</filter-name>
|
||||||
<filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
|
<filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
|
||||||
<!-- If you are wiring Solr into a larger web application which controls
|
|
||||||
the web context root, you will probably want to mount Solr under
|
|
||||||
a path prefix (app.war with /app/solr mounted into it, for example).
|
|
||||||
You will need to put this prefix in front of the SolrDispatchFilter
|
|
||||||
url-pattern mapping too (/solr/*), and also on any paths for
|
|
||||||
legacy Solr servlet mappings you may be using.
|
|
||||||
For the Admin UI to work properly in a path-prefixed configuration,
|
|
||||||
the admin folder containing the resources needs to be under the app context root
|
|
||||||
named to match the path-prefix. For example:
|
|
||||||
|
|
||||||
.war
|
|
||||||
xxx
|
|
||||||
js
|
|
||||||
main.js
|
|
||||||
-->
|
|
||||||
<!--
|
<!--
|
||||||
<init-param>
|
Exclude patterns is a list of directories that would be short circuited by the
|
||||||
<param-name>path-prefix</param-name>
|
SolrDispatchFilter. It includes all Admin UI related static content.
|
||||||
<param-value>/xxx</param-value>
|
NOTE: It is NOT a pattern but only matches the start of the HTTP ServletPath.
|
||||||
</init-param>
|
|
||||||
-->
|
-->
|
||||||
|
<init-param>
|
||||||
|
<param-name>excludePatterns</param-name>
|
||||||
|
<param-value>/css/*,/js/*,/img/*,/tpl/*</param-value>
|
||||||
|
</init-param>
|
||||||
</filter>
|
</filter>
|
||||||
|
|
||||||
<filter-mapping>
|
<filter-mapping>
|
||||||
|
|
Loading…
Reference in New Issue