From 8418f56e944e7e29eae9715c84e99035dc75b0ef Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 2 Aug 2019 22:05:07 +0200 Subject: [PATCH] Fixes #3856 - Different behaviour with maxFormContentSize=0 if Content-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 --- .../java/org/eclipse/jetty/server/Request.java | 15 +++++++++++++++ .../jetty/server/handler/ContextHandler.java | 16 ++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 408420e6874..c61e637a86f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -507,6 +507,11 @@ public class Request implements HttpServletRequest 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) @@ -525,6 +530,16 @@ public class Request implements HttpServletRequest } } + 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() { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index c572c9839e0..85574490c67 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -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. @@ -195,8 +197,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu 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; @@ -785,12 +787,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu @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)