Merge remote-tracking branch 'origin/master' into jetty-8
Conflicts: jetty-servlets/src/test/java/org/eclipse/jetty/servlets/gzip/GzipTester.java
This commit is contained in:
commit
f144b6562e
|
@ -295,7 +295,6 @@ public class HttpFields
|
|||
/* -------------------------------------------------------------- */
|
||||
private final ArrayList<Field> _fields = new ArrayList<Field>(20);
|
||||
private final HashMap<Buffer,Field> _names = new HashMap<Buffer,Field>(32);
|
||||
private final int _maxCookieVersion;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -303,19 +302,8 @@ public class HttpFields
|
|||
*/
|
||||
public HttpFields()
|
||||
{
|
||||
_maxCookieVersion=1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public HttpFields(int maxCookieVersion)
|
||||
{
|
||||
_maxCookieVersion=maxCookieVersion;
|
||||
}
|
||||
|
||||
|
||||
// TODO externalize this cache so it can be configurable
|
||||
private static ConcurrentMap<String, Buffer> __cache = new ConcurrentHashMap<String, Buffer>();
|
||||
private static int __cacheSize = Integer.getInteger("org.eclipse.jetty.http.HttpFields.CACHE",2000);
|
||||
|
@ -971,7 +959,7 @@ public class HttpFields
|
|||
final boolean isHttpOnly,
|
||||
int version)
|
||||
{
|
||||
String delim=_maxCookieVersion==0?"":__COOKIE_DELIM;
|
||||
String delim=__COOKIE_DELIM;
|
||||
|
||||
// Check arguments
|
||||
if (name == null || name.length() == 0)
|
||||
|
@ -980,29 +968,18 @@ public class HttpFields
|
|||
// Format value and params
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
String name_value_params;
|
||||
boolean quoted = QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
|
||||
QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
|
||||
buf.append('=');
|
||||
String start=buf.toString();
|
||||
if (value != null && value.length() > 0)
|
||||
quoted|=QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
|
||||
|
||||
// upgrade to version 1 cookies if quoted.
|
||||
if (quoted&&version==0 && _maxCookieVersion>=1)
|
||||
version=1;
|
||||
QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
|
||||
|
||||
if (version>_maxCookieVersion)
|
||||
version=_maxCookieVersion;
|
||||
|
||||
if (version > 0)
|
||||
if (comment != null && comment.length() > 0)
|
||||
{
|
||||
buf.append(";Version=");
|
||||
buf.append(version);
|
||||
if (comment != null && comment.length() > 0)
|
||||
{
|
||||
buf.append(";Comment=");
|
||||
QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
|
||||
}
|
||||
buf.append(";Comment=");
|
||||
QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
|
||||
}
|
||||
|
||||
if (path != null && path.length() > 0)
|
||||
{
|
||||
buf.append(";Path=");
|
||||
|
@ -1019,23 +996,19 @@ public class HttpFields
|
|||
|
||||
if (maxAge >= 0)
|
||||
{
|
||||
// Always add the expires param as some browsers still don't handle max-age
|
||||
buf.append(";Expires=");
|
||||
if (maxAge == 0)
|
||||
buf.append(__01Jan1970_COOKIE);
|
||||
else
|
||||
formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
|
||||
|
||||
// Always add the expires param as some browsers still don't handle max-age
|
||||
buf.append(";Expires=");
|
||||
if (maxAge == 0)
|
||||
buf.append(__01Jan1970_COOKIE);
|
||||
else
|
||||
formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
|
||||
|
||||
if (version >0)
|
||||
{
|
||||
buf.append(";Max-Age=");
|
||||
buf.append(maxAge);
|
||||
}
|
||||
}
|
||||
else if (version > 0)
|
||||
{
|
||||
buf.append(";Discard");
|
||||
}
|
||||
|
||||
if (isSecure)
|
||||
buf.append(";Secure");
|
||||
|
|
|
@ -361,28 +361,18 @@ public class HttpFieldsTest
|
|||
fields.clear();
|
||||
fields.addSetCookie("everything","wrong","wrong","wrong",0,"to be replaced",true,true,0);
|
||||
fields.addSetCookie("everything","value","domain","path",0,"comment",true,true,0);
|
||||
assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",fields.getStringField("Set-Cookie"));
|
||||
assertEquals("everything=value;Comment=comment;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",fields.getStringField("Set-Cookie"));
|
||||
Enumeration<String> e =fields.getValues("Set-Cookie");
|
||||
assertTrue(e.hasMoreElements());
|
||||
assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",e.nextElement());
|
||||
assertEquals("everything=value;Comment=comment;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",e.nextElement());
|
||||
assertFalse(e.hasMoreElements());
|
||||
assertEquals("Thu, 01 Jan 1970 00:00:00 GMT",fields.getStringField("Expires"));
|
||||
|
||||
assertEquals("Thu, 01 Jan 1970 00:00:00 GMT",fields.getStringField("Expires"));
|
||||
|
||||
fields.clear();
|
||||
fields.addSetCookie("ev erything","va lue","do main","pa th",1,"co mment",true,true,2);
|
||||
String setCookie=fields.getStringField("Set-Cookie");
|
||||
assertTrue(setCookie.startsWith("\"ev erything\"=\"va lue\";Version=1;Comment=\"co mment\";Path=\"pa th\";Domain=\"do main\";Expires="));
|
||||
assertTrue(setCookie.startsWith("\"ev erything\"=\"va lue\";Comment=\"co mment\";Path=\"pa th\";Domain=\"do main\";Expires="));
|
||||
assertTrue(setCookie.endsWith("GMT;Max-Age=1;Secure;HttpOnly"));
|
||||
|
||||
fields.clear();
|
||||
fields.addSetCookie("name","value",null,null,-1,null,false,false,0);
|
||||
setCookie=fields.getStringField("Set-Cookie");
|
||||
assertEquals(-1,setCookie.indexOf("Version="));
|
||||
fields.clear();
|
||||
fields.addSetCookie("name","v a l u e",null,null,-1,null,false,false,0);
|
||||
setCookie=fields.getStringField("Set-Cookie");
|
||||
assertEquals(17,setCookie.indexOf("Version=1"));
|
||||
|
||||
fields.clear();
|
||||
fields.addSetCookie("json","{\"services\":[\"cwa\", \"aa\"]}",null,null,-1,null,false,false,-1);
|
||||
|
@ -401,12 +391,6 @@ public class HttpFieldsTest
|
|||
e=fields.getValues("Set-Cookie");
|
||||
assertEquals("name=more;Domain=domain",e.nextElement());
|
||||
assertEquals("foo=bob;Domain=domain",e.nextElement());
|
||||
|
||||
fields=new HttpFields(0);
|
||||
fields.addSetCookie("name","value==",null,null,-1,null,false,false,0);
|
||||
setCookie=fields.getStringField("Set-Cookie");
|
||||
assertEquals("name=value==",setCookie);
|
||||
|
||||
}
|
||||
|
||||
private Set<String> enum2set(Enumeration<String> e)
|
||||
|
|
|
@ -147,7 +147,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
|
|||
HttpBuffers ab = (HttpBuffers)_connector;
|
||||
_parser = newHttpParser(ab.getRequestBuffers(), endpoint, new RequestHandler());
|
||||
_requestFields = new HttpFields();
|
||||
_responseFields = new HttpFields(server.getMaxCookieVersion());
|
||||
_responseFields = new HttpFields();
|
||||
_request = new Request(this);
|
||||
_response = new Response(this);
|
||||
_generator = newHttpGenerator(ab.getResponseBuffers(), endpoint);
|
||||
|
@ -165,7 +165,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
|
|||
_connector = connector;
|
||||
_parser = parser;
|
||||
_requestFields = new HttpFields();
|
||||
_responseFields = new HttpFields(server.getMaxCookieVersion());
|
||||
_responseFields = new HttpFields();
|
||||
_request = request;
|
||||
_response = new Response(this);
|
||||
_generator = generator;
|
||||
|
|
|
@ -137,7 +137,7 @@ public class Response implements HttpServletResponse
|
|||
if (i>=0)
|
||||
{
|
||||
http_only=true;
|
||||
comment=comment.substring(i,i+HTTP_ONLY_COMMENT.length()).trim();
|
||||
comment=comment.replace(HTTP_ONLY_COMMENT,"").trim();
|
||||
if (comment.length()==0)
|
||||
comment=null;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,6 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
private boolean _sendDateHeader = false; //send Date: header
|
||||
private int _graceful=0;
|
||||
private boolean _stopAtShutdown;
|
||||
private int _maxCookieVersion=1;
|
||||
private boolean _dumpAfterStart=false;
|
||||
private boolean _dumpBeforeStop=false;
|
||||
private boolean _uncheckedPrintWriter=false;
|
||||
|
@ -452,21 +451,20 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the maximum cookie version.
|
||||
* @return the maximum set-cookie version sent by this server
|
||||
/**
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMaxCookieVersion()
|
||||
{
|
||||
return _maxCookieVersion;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set the maximum cookie version.
|
||||
* @param maxCookieVersion the maximum set-cookie version sent by this server
|
||||
/**
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMaxCookieVersion(int maxCookieVersion)
|
||||
{
|
||||
_maxCookieVersion = maxCookieVersion;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -518,7 +518,7 @@ public class ResponseTest
|
|||
|
||||
String set = response.getHttpFields().getStringField("Set-Cookie");
|
||||
|
||||
assertEquals("name=value;Path=/path;Domain=domain;Secure;HttpOnly",set);
|
||||
assertEquals("name=value;Comment=comment;Path=/path;Domain=domain;Secure;HttpOnly",set);
|
||||
}
|
||||
|
||||
private Response newResponse()
|
||||
|
|
|
@ -63,7 +63,37 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* This filter extends {@link UserAgentFilter} and if the the initParameter <code>excludedAgents</code>
|
||||
* is set to a comma separated list of user agents, then these agents will be excluded from gzip content.
|
||||
* </p>
|
||||
* <p>Init Parameters:</p>
|
||||
* <PRE>
|
||||
* bufferSize The output buffer size. Defaults to 8192. Be careful as values <= 0 will lead to an
|
||||
* {@link IllegalArgumentException}.
|
||||
* @see java.util.zip.GZIPOutputStream#GZIPOutputStream(java.io.OutputStream, int)
|
||||
* @see java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream, Deflater, int)
|
||||
*
|
||||
* minGzipSize Content will only be compressed if content length is either unknown or greater
|
||||
* than <code>minGzipSize</code>.
|
||||
*
|
||||
* deflateCompressionLevel The compression level used for deflate compression. (0-9).
|
||||
* @see java.util.zip.Deflater#Deflater(int, boolean)
|
||||
*
|
||||
* deflateNoWrap The noWrap setting for deflate compression. Defaults to true. (true/false)
|
||||
* @see java.util.zip.Deflater#Deflater(int, boolean)
|
||||
*
|
||||
* mimeTypes Comma separated list of mime types to compress. See description above.
|
||||
*
|
||||
* excludedAgents Comma separated list of user agents to exclude from compression. Does a
|
||||
* {@link String#contains(CharSequence)} to check if the excluded agent occurs
|
||||
* in the user-agent header. If it does -> no compression
|
||||
*
|
||||
* excludeAgentPatterns Same as excludedAgents, but accepts regex patterns for more complex matching.
|
||||
*
|
||||
* excludePaths Comma separated list of paths to exclude from compression.
|
||||
* Does a {@link String#startsWith(String)} comparison to check if the path matches.
|
||||
* If it does match -> no compression. To match subpaths use <code>excludePathPatterns</code>
|
||||
* instead.
|
||||
*
|
||||
* excludePathPatterns Same as excludePath, but accepts regex patterns for more complex matching.
|
||||
* </PRE>
|
||||
*/
|
||||
public class GzipFilter extends UserAgentFilter
|
||||
{
|
||||
|
@ -74,6 +104,8 @@ public class GzipFilter extends UserAgentFilter
|
|||
protected Set<String> _mimeTypes;
|
||||
protected int _bufferSize=8192;
|
||||
protected int _minGzipSize=256;
|
||||
protected int _deflateCompressionLevel=Deflater.DEFAULT_COMPRESSION;
|
||||
protected boolean _deflateNoWrap = true;
|
||||
protected Set<String> _excludedAgents;
|
||||
protected Set<Pattern> _excludedAgentPatterns;
|
||||
protected Set<String> _excludedPaths;
|
||||
|
@ -97,6 +129,14 @@ public class GzipFilter extends UserAgentFilter
|
|||
if (tmp!=null)
|
||||
_minGzipSize=Integer.parseInt(tmp);
|
||||
|
||||
tmp=filterConfig.getInitParameter("deflateCompressionLevel");
|
||||
if (tmp!=null)
|
||||
_deflateCompressionLevel=Integer.parseInt(tmp);
|
||||
|
||||
tmp=filterConfig.getInitParameter("deflateNoWrap");
|
||||
if (tmp!=null)
|
||||
_deflateNoWrap=Boolean.parseBoolean(tmp);
|
||||
|
||||
tmp=filterConfig.getInitParameter("mimeTypes");
|
||||
if (tmp!=null)
|
||||
{
|
||||
|
@ -256,7 +296,7 @@ public class GzipFilter extends UserAgentFilter
|
|||
@Override
|
||||
protected DeflaterOutputStream createStream() throws IOException
|
||||
{
|
||||
return new DeflaterOutputStream(_response.getOutputStream(),new Deflater(Deflater.DEFAULT_COMPRESSION));
|
||||
return new DeflaterOutputStream(_response.getOutputStream(),new Deflater(_deflateCompressionLevel,_deflateNoWrap));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class IncludableGzipFilter extends GzipFilter
|
|||
@Override
|
||||
protected DeflaterOutputStream createStream() throws IOException
|
||||
{
|
||||
return new DeflaterOutputStream(_response.getOutputStream(),new Deflater(Deflater.DEFAULT_COMPRESSION));
|
||||
return new DeflaterOutputStream(_response.getOutputStream(),new Deflater(_deflateCompressionLevel, _deflateNoWrap));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package org.eclipse.jetty.servlets;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -17,6 +22,7 @@ import java.util.Collection;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
|
@ -186,7 +192,7 @@ public class GzipWithPipeliningTest
|
|||
InputStream uncompressedStream = null;
|
||||
if (GzipFilter.DEFLATE.equals(encodingHeader))
|
||||
{
|
||||
uncompressedStream = new InflaterInputStream(rawInputStream);
|
||||
uncompressedStream = new InflaterInputStream(rawInputStream, new Inflater(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -139,7 +140,7 @@ public class IncludableGzipFilterTest
|
|||
}
|
||||
else if (compressionType.equals(GzipFilter.DEFLATE))
|
||||
{
|
||||
testIn = new InflaterInputStream(compressedResponseStream);
|
||||
testIn = new InflaterInputStream(compressedResponseStream, new Inflater(true));
|
||||
}
|
||||
ByteArrayOutputStream testOut = new ByteArrayOutputStream();
|
||||
IO.copy(testIn,testOut);
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.util.Enumeration;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import java.util.zip.Inflater;
|
||||
import javax.servlet.DispatcherType;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class GzipTester
|
|||
}
|
||||
else if (compressionType.equals(GzipFilter.DEFLATE))
|
||||
{
|
||||
in = new InflaterInputStream(bais);
|
||||
in = new InflaterInputStream(bais, new Inflater(true));
|
||||
}
|
||||
out = new ByteArrayOutputStream();
|
||||
IO.copy(in,out);
|
||||
|
|
|
@ -94,7 +94,9 @@ public class StandardStream implements IStream
|
|||
public boolean isHalfClosed()
|
||||
{
|
||||
CloseState closeState = this.closeState;
|
||||
return closeState == CloseState.LOCALLY_CLOSED || closeState == CloseState.REMOTELY_CLOSED;
|
||||
return closeState == CloseState.LOCALLY_CLOSED ||
|
||||
closeState == CloseState.REMOTELY_CLOSED ||
|
||||
closeState == CloseState.CLOSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue