Skip to content

Commit

Permalink
Fixes #3856 - Different behaviour with maxFormContentSize=0 if Conten…
Browse files Browse the repository at this point in the history
…t-Length header is present/missing.

Changed the logic to lookup server attributes if there is no context.
This fixes a failing test that was explicitly setting the server
attributes after start.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Aug 2, 2019
1 parent 2488c96 commit 8418f56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 15 additions & 0 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Expand Up @@ -507,6 +507,11 @@ public void extractFormParameters(MultiMap<String> params)
maxFormContentSize = contextHandler.getMaxFormContentSize();
maxFormKeys = contextHandler.getMaxFormKeys();
}
else
{
maxFormContentSize = lookupServerAttribute(ContextHandler.MAX_FORM_CONTENT_SIZE_KEY, maxFormContentSize);
maxFormKeys = lookupServerAttribute(ContextHandler.MAX_FORM_KEYS_KEY, maxFormKeys);
}

int contentLength = getContentLength();
if (maxFormContentSize >= 0 && contentLength > maxFormContentSize)
Expand All @@ -525,6 +530,16 @@ public void extractFormParameters(MultiMap<String> params)
}
}

private int lookupServerAttribute(String key, int dftValue)
{
Object attribute = _channel.getServer().getAttribute(key);
if (attribute instanceof Number)
return ((Number)attribute).intValue();
else if (attribute instanceof String)
return Integer.parseInt((String)attribute);
return dftValue;
}

@Override
public AsyncContext getAsyncContext()
{
Expand Down
Expand Up @@ -140,9 +140,11 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
* for the attribute value.
*/
public static final String MANAGED_ATTRIBUTES = "org.eclipse.jetty.server.context.ManagedAttributes";
private static final int NOT_INITIALIZED = -2;
public static final int DEFAULT_MAX_FORM_CONTENT_SIZE = 200000;

public static final String MAX_FORM_KEYS_KEY = "org.eclipse.jetty.server.Request.maxFormKeys";
public static final String MAX_FORM_CONTENT_SIZE_KEY = "org.eclipse.jetty.server.Request.maxFormContentSize";
public static final int DEFAULT_MAX_FORM_KEYS = 1000;
public static final int DEFAULT_MAX_FORM_CONTENT_SIZE = 200000;

/**
* Get the current ServletContext implementation.
Expand Down Expand Up @@ -195,8 +197,8 @@ public static void setServerInfo(String serverInfo)

private Logger _logger;
private boolean _allowNullPathInfo;
private int _maxFormKeys = NOT_INITIALIZED;
private int _maxFormContentSize = NOT_INITIALIZED;
private int _maxFormKeys = Integer.getInteger(MAX_FORM_KEYS_KEY, DEFAULT_MAX_FORM_KEYS);
private int _maxFormContentSize = Integer.getInteger(MAX_FORM_CONTENT_SIZE_KEY, DEFAULT_MAX_FORM_CONTENT_SIZE);
private boolean _compactPath = false;
private boolean _usingSecurityManager = System.getSecurityManager() != null;

Expand Down Expand Up @@ -785,12 +787,6 @@ public void setLogger(Logger logger)
@Override
protected void doStart() throws Exception
{
if (_maxFormKeys == NOT_INITIALIZED)
_maxFormKeys = lookup("org.eclipse.jetty.server.Request.maxFormKeys", DEFAULT_MAX_FORM_KEYS);

if (_maxFormContentSize == NOT_INITIALIZED)
_maxFormContentSize = lookup("org.eclipse.jetty.server.Request.maxFormContentSize", DEFAULT_MAX_FORM_CONTENT_SIZE);

_availability = Availability.STARTING;

if (_contextPath == null)
Expand Down

0 comments on commit 8418f56

Please sign in to comment.