373306 Set default user agent extraction pattern for UserAgentFilter
This commit is contained in:
parent
de8a1b3fe4
commit
386249f504
|
@ -50,7 +50,8 @@ import javax.servlet.http.HttpServletRequest;
|
|||
*/
|
||||
public class UserAgentFilter implements Filter
|
||||
{
|
||||
private Pattern _pattern;
|
||||
private static final String __defaultPattern = "(?:Mozilla[^\\(]*\\(compatible;\\s*+([^;]*);.*)|(?:.*?([^\\s]+/[^\\s]+).*)";
|
||||
private Pattern _pattern = Pattern.compile(__defaultPattern);
|
||||
private Map _agentCache = new ConcurrentHashMap();
|
||||
private int _agentCacheSize=1024;
|
||||
private String _attribute;
|
||||
|
|
|
@ -137,4 +137,26 @@ public class GzipFilterDefaultTest
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserAgentExclusion() throws Exception
|
||||
{
|
||||
GzipTester tester = new GzipTester(testingdir);
|
||||
|
||||
FilterHolder holder = tester.setContentServlet(DefaultServlet.class);
|
||||
holder.setInitParameter("excludedAgents", "foo");
|
||||
tester.setUserAgent("foo");
|
||||
|
||||
int filesize = GzipResponseWrapper.DEFAULT_BUFFER_SIZE * 4;
|
||||
tester.prepareServerFile("file.txt",filesize);
|
||||
|
||||
try
|
||||
{
|
||||
tester.start();
|
||||
tester.assertIsResponseNotGzipCompressed("file.txt", filesize, HttpStatus.OK_200);
|
||||
}
|
||||
finally
|
||||
{
|
||||
tester.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ public class GzipTester
|
|||
{
|
||||
private Class<? extends GzipFilter> gzipFilterClass = GzipFilter.class;
|
||||
private String encoding = "ISO8859_1";
|
||||
private String userAgent = null;
|
||||
private ServletTester servletTester;
|
||||
private TestingDir testdir;
|
||||
|
||||
|
@ -61,6 +62,8 @@ public class GzipTester
|
|||
request.setVersion("HTTP/1.0");
|
||||
request.setHeader("Host","tester");
|
||||
request.setHeader("Accept-Encoding","gzip");
|
||||
if (this.userAgent != null)
|
||||
request.setHeader("User-Agent", this.userAgent);
|
||||
request.setURI("/context/" + requestedFilename);
|
||||
|
||||
// Issue the request
|
||||
|
@ -126,6 +129,8 @@ public class GzipTester
|
|||
request.setVersion("HTTP/1.0");
|
||||
request.setHeader("Host","tester");
|
||||
request.setHeader("Accept-Encoding","gzip");
|
||||
if (this.userAgent != null)
|
||||
request.setHeader("User-Agent", this.userAgent);
|
||||
request.setURI("/context/" + requestedFilename);
|
||||
|
||||
// Issue the request
|
||||
|
@ -211,6 +216,8 @@ public class GzipTester
|
|||
request.setVersion("HTTP/1.0");
|
||||
request.setHeader("Host","tester");
|
||||
request.setHeader("Accept-Encoding","gzip");
|
||||
if (this.userAgent != null)
|
||||
request.setHeader("User-Agent", this.userAgent);
|
||||
if (filename == null)
|
||||
request.setURI("/context/");
|
||||
else
|
||||
|
@ -384,6 +391,11 @@ public class GzipTester
|
|||
{
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public void setUserAgent(String ua)
|
||||
{
|
||||
this.userAgent = ua;
|
||||
}
|
||||
|
||||
public void start() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue