Issue #3041 separate CookieCompliance for parsing and generation (#3048)

* Issue #3041 separate CookieCompliance for parsing and generation

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* improved documentation

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* use only getters

Signed-off-by: Greg Wilkins <gregw@webtide.com>

* Rename setters to avoid setSetXxxx

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2018-11-07 10:03:18 +01:00 committed by GitHub
parent 872eafef06
commit cf2de4411c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 108 additions and 25 deletions

View File

@ -64,7 +64,8 @@
<Set name="maxErrorDispatches"><Property name="jetty.httpConfig.maxErrorDispatches" default="10"/></Set>
<Set name="blockingTimeout"><Property deprecated="jetty.httpConfig.blockingTimeout" name="jetty.httpConfig.blockingTimeout.DEPRECATED" default="-1"/></Set>
<Set name="persistentConnectionsEnabled"><Property name="jetty.httpConfig.persistentConnectionsEnabled" default="true"/></Set>
<Set name="cookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.cookieCompliance" default="RFC6265"/></Arg></Call></Set>
<Set name="requestCookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.requestCookieCompliance" deprecated="jetty.httpConfig.cookieCompliance" default="RFC6265"/></Arg></Call></Set>
<Set name="responseCookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.responseCookieCompliance" default="RFC6265"/></Arg></Call></Set>
<Set name="multiPartFormDataCompliance"><Call class="org.eclipse.jetty.server.MultiPartFormDataCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.multiPartFormDataCompliance" default="RFC7578"/></Arg></Call></Set>
</New>

View File

@ -62,8 +62,11 @@ patch-module: servlet.api=lib/jetty-schemas-3.1.jar
## Maximum number of error dispatches to prevent looping
# jetty.httpConfig.maxErrorDispatches=10
## Cookie compliance mode of: RFC2965, RFC6265
# jetty.httpConfig.cookieCompliance=RFC6265
## Cookie compliance mode for parsing request Cookie headers: RFC2965, RFC6265
# jetty.httpConfig.requestCookieCompliance=RFC6265
## Cookie compliance mode for generating response Set-Cookie: RFC2965, RFC6265
# jetty.httpConfig.responseCookieCompliance=RFC6265
## multipart/form-data compliance mode of: LEGACY(slow), RFC7578(fast)
# jetty.httpConfig.multiPartFormDataCompliance=LEGACY

View File

@ -31,6 +31,8 @@ import org.eclipse.jetty.util.TreeTrie;
import org.eclipse.jetty.util.Trie;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.DumpableCollection;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -46,7 +48,7 @@ import org.eclipse.jetty.util.log.Logger;
* </p>
*/
@ManagedObject("HTTP Configuration")
public class HttpConfiguration
public class HttpConfiguration implements Dumpable
{
private static final Logger LOG = Log.getLogger(HttpConfiguration.class);
@ -70,7 +72,8 @@ public class HttpConfiguration
private int _maxErrorDispatches = 10;
private long _minRequestDataRate;
private long _minResponseDataRate;
private CookieCompliance _cookieCompliance = CookieCompliance.RFC6265;
private CookieCompliance _requestCookieCompliance = CookieCompliance.RFC6265;
private CookieCompliance _responseCookieCompliance = CookieCompliance.RFC6265;
private MultiPartFormDataCompliance _multiPartCompliance = MultiPartFormDataCompliance.LEGACY; // TODO change default in jetty-10
private boolean _notifyRemoteAsyncErrors = true;
@ -133,7 +136,8 @@ public class HttpConfiguration
_maxErrorDispatches=config._maxErrorDispatches;
_minRequestDataRate=config._minRequestDataRate;
_minResponseDataRate=config._minResponseDataRate;
_cookieCompliance=config._cookieCompliance;
_requestCookieCompliance =config._requestCookieCompliance;
_responseCookieCompliance =config._responseCookieCompliance;
_notifyRemoteAsyncErrors=config._notifyRemoteAsyncErrors;
}
@ -531,19 +535,58 @@ public class HttpConfiguration
_minResponseDataRate = bytesPerSecond;
}
public CookieCompliance getCookieCompliance()
/**
* @see #getResponseCookieCompliance()
* @return The CookieCompliance used for parsing request <code>Cookie</code> headers.
*/
public CookieCompliance getRequestCookieCompliance()
{
return _cookieCompliance;
}
public void setCookieCompliance(CookieCompliance cookieCompliance)
{
_cookieCompliance = cookieCompliance==null?CookieCompliance.RFC6265:cookieCompliance;
return _requestCookieCompliance;
}
/**
* @see #getRequestCookieCompliance()
* @return The CookieCompliance used for generating response <code>Set-Cookie</code> headers
*/
public CookieCompliance getResponseCookieCompliance()
{
return _responseCookieCompliance;
}
/**
* @see #setRequestCookieCompliance(CookieCompliance)
* @param cookieCompliance The CookieCompliance to use for parsing request <code>Cookie</code> headers.
*/
public void setRequestCookieCompliance(CookieCompliance cookieCompliance)
{
_requestCookieCompliance = cookieCompliance==null?CookieCompliance.RFC6265:cookieCompliance;
}
/**
* @see #setResponseCookieCompliance(CookieCompliance)
* @param cookieCompliance The CookieCompliance to use for generating response <code>Set-Cookie</code> headers
*/
public void setResponseCookieCompliance(CookieCompliance cookieCompliance)
{
_responseCookieCompliance = cookieCompliance==null?CookieCompliance.RFC6265:cookieCompliance;
}
@Deprecated
public void setCookieCompliance(CookieCompliance compliance)
{
setRequestCookieCompliance(compliance);
}
@Deprecated
public CookieCompliance getCookieCompliance()
{
return getRequestCookieCompliance();
}
@Deprecated
public boolean isCookieCompliance(CookieCompliance compliance)
{
return _cookieCompliance.equals(compliance);
return _requestCookieCompliance.equals(compliance);
}
/**
@ -579,15 +622,51 @@ public class HttpConfiguration
return _notifyRemoteAsyncErrors;
}
@Override public String dump()
{
return Dumpable.dump(this);
}
@Override public void dump(Appendable out, String indent) throws IOException
{
Dumpable.dumpObjects(out,indent,this,
new DumpableCollection("customizers",_customizers),
new DumpableCollection("formEncodedMethods",_formEncodedMethods.keySet()),
"outputBufferSize=" + _outputBufferSize,
"outputAggregationSize=" + _outputAggregationSize,
"requestHeaderSize=" + _requestHeaderSize,
"responseHeaderSize=" + _responseHeaderSize,
"headerCacheSize=" + _headerCacheSize,
"secureScheme=" + _secureScheme,
"securePort=" + _securePort,
"idleTimeout=" + _idleTimeout,
"blockingTimeout=" + _blockingTimeout,
"sendDateHeader=" + _sendDateHeader,
"sendServerVersion=" + _sendServerVersion,
"sendXPoweredBy=" + _sendXPoweredBy,
"delayDispatchUntilContent=" + _delayDispatchUntilContent,
"persistentConnectionsEnabled=" + _persistentConnectionsEnabled,
"maxErrorDispatches=" + _maxErrorDispatches,
"minRequestDataRate=" + _minRequestDataRate,
"minResponseDataRate=" + _minResponseDataRate,
"cookieCompliance=" + _requestCookieCompliance,
"setRequestCookieCompliance=" + _responseCookieCompliance,
"notifyRemoteAsyncErrors=" + _notifyRemoteAsyncErrors
);
}
@Override
public String toString()
{
return String.format("%s@%x{%d/%d,%d/%d,%s://:%d,%s}",
this.getClass().getSimpleName(),
hashCode(),
_outputBufferSize, _outputAggregationSize,
_requestHeaderSize,_responseHeaderSize,
_secureScheme,_securePort,
_customizers);
this.getClass().getSimpleName(),
hashCode(),
_outputBufferSize,
_outputAggregationSize,
_requestHeaderSize,
_responseHeaderSize,
_secureScheme,
_securePort,
_customizers);
}
}

View File

@ -770,7 +770,7 @@ public class Request implements HttpServletRequest
if (field.getHeader()==HttpHeader.COOKIE)
{
if (_cookies==null)
_cookies = new CookieCutter(getHttpChannel().getHttpConfiguration().getCookieCompliance());
_cookies = new CookieCutter(getHttpChannel().getHttpConfiguration().getRequestCookieCompliance());
_cookies.addCookieField(field.getValue());
}
}
@ -2057,7 +2057,7 @@ public class Request implements HttpServletRequest
public void setCookies(Cookie[] cookies)
{
if (_cookies == null)
_cookies = new CookieCutter(getHttpChannel().getHttpConfiguration().getCookieCompliance());
_cookies = new CookieCutter(getHttpChannel().getHttpConfiguration().getRequestCookieCompliance());
_cookies.setCookies(cookies);
}

View File

@ -172,7 +172,7 @@ public class Response implements HttpServletResponse
throw new IllegalArgumentException("Cookie.name cannot be blank/null");
}
if (getHttpChannel().getHttpConfiguration().isCookieCompliance(CookieCompliance.RFC2965))
if (getHttpChannel().getHttpConfiguration().getResponseCookieCompliance()==CookieCompliance.RFC2965)
addSetRFC2965Cookie(
cookie.getName(),
cookie.getValue(),
@ -217,7 +217,7 @@ public class Response implements HttpServletResponse
throw new IllegalArgumentException("Cookie.name cannot be blank/null");
}
if (getHttpChannel().getHttpConfiguration().isCookieCompliance(CookieCompliance.RFC2965))
if (getHttpChannel().getHttpConfiguration().getResponseCookieCompliance()==CookieCompliance.RFC2965)
addSetRFC2965Cookie(cookie.getName(),
cookie.getValue(),
cookie.getDomain(),

View File

@ -944,7 +944,7 @@ public class ResponseTest
public void testAddCookieComplianceRFC2965() throws Exception
{
Response response = getResponse();
response.getHttpChannel().getHttpConfiguration().setCookieCompliance(CookieCompliance.RFC2965);
response.getHttpChannel().getHttpConfiguration().setResponseCookieCompliance(CookieCompliance.RFC2965);
Cookie cookie = new Cookie("name", "value");
cookie.setDomain("domain");