Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-60409] --requestFormContentSize no longer works #95

Merged
merged 2 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/winstone/HostConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public void preConfigure() throws Exception {
} finally {
t.setContextClassLoader(ccl);
}
int maxParameterCount = Option.MAX_PARAM_COUNT.get(args);
if (maxParameterCount > 0) {
setMaxFormKeys(maxParameterCount);
}
setMaxFormContentSize(Option.REQUEST_FORM_CONTENT_SIZE.get(args));
}

@Override
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/winstone/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ public Launcher(Map args) throws IOException {
this.server = new Server(queuedThreadPool);


int maxParameterCount = Option.MAX_PARAM_COUNT.get(args);
if (maxParameterCount>0) {
server.setAttribute("org.eclipse.jetty.server.Request.maxFormKeys",maxParameterCount);
}
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize",
Option.REQUEST_FORM_CONTENT_SIZE.get(args));

// Open the web apps
this.hostGroup = new HostGroup(server, commonLibCL,
commonLibCLPaths.toArray(new File[0]), args);
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/winstone/FormSubmissionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package winstone;

import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

public class FormSubmissionTest extends AbstractWinstoneTest {

@Issue("JENKINS-60409")
@Test
public void largeForm() throws Exception {
Map<String,String> args = new HashMap<String,String>();
args.put("warfile", "target/test-classes/test.war");
args.put("prefix", "/");
args.put("httpPort", "59009");
args.put("httpListenAddress", "127.0.0.2");
/* To see it fail:
args.put("requestFormContentSize", "999");
*/
winstone = new Launcher(args);

for (int size = 1; size <= 9_999_999; size *= 3) {
System.out.println("trying size " + size);
WebRequest wreq = new PostMethodWebRequest("http://127.0.0.2:59009/AcceptFormServlet");
StringBuilder b = new StringBuilder();
for (int i = 0; i < size; i++) {
b.append('.');
}
wreq.setParameter("x", b.toString());
WebResponse wresp = wc.getResponse(wreq);
try (InputStream content = wresp.getInputStream()) {
assertTrue("Loading AcceptFormServlet at size " + size, content.available() > 0);
assertEquals("correct response at size " + size, "received " + (size + "x=".length()) + " bytes", IOUtils.toString(content, StandardCharsets.US_ASCII));
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package winstone.testApplication.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AcceptFormServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/plain");
try (PrintWriter pw = resp.getWriter()) {
try {
req.getParameterNames();
} catch (Exception x) {
x.printStackTrace(pw);
return;
}
pw.print("received " + req.getContentLength() + " bytes");
}
}

}
12 changes: 11 additions & 1 deletion src/testwebapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


<servlet>
<servlet-name>AcceptFormServlet</servlet-name>
<servlet-class>winstone.testApplication.servlets.AcceptFormServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>UnavailableAtInitServlet</servlet-name>
<servlet-class>winstone.testApplication.servlets.UnavailableServlet</servlet-class>
Expand Down Expand Up @@ -81,6 +86,11 @@
<url-pattern>/CountRequestsServlet</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>AcceptFormServlet</servlet-name>
<url-pattern>/AcceptFormServlet</url-pattern>
</servlet-mapping>

<!-- test that an explicit mapping overrides the default JSP one -->
<servlet-mapping>
<servlet-name>loadOnStartupJSP</servlet-name>
Expand Down