aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2012-08-24 05:07:36 (EDT)
committerThomas Becker2012-08-29 09:53:51 (EDT)
commitfe88df1def6f8e3b15250c7865370d8c61a3db94 (patch)
tree910c2907c630427e13899416a998e77272400b1c
parenta77093dd94110c971e9e139dcc9f6d54b14f2830 (diff)
downloadorg.eclipse.jetty.project-fe88df1def6f8e3b15250c7865370d8c61a3db94.zip
org.eclipse.jetty.project-fe88df1def6f8e3b15250c7865370d8c61a3db94.tar.gz
org.eclipse.jetty.project-fe88df1def6f8e3b15250c7865370d8c61a3db94.tar.bz2
jetty-9 move SimpleHttpParser and SimpleHttpResponse to jetty-test-helper
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java20
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java122
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java46
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java46
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/util/SimpleHttpParser.java201
5 files changed, 181 insertions, 254 deletions
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java
index 3d96934..8b15d0c 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java
@@ -25,13 +25,13 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.URISyntaxException;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.eclipse.jetty.server.util.SimpleHttpParser;
+import org.eclipse.jetty.toolchain.test.http.SimpleHttpParser;
+import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog;
import org.junit.After;
@@ -69,7 +69,7 @@ public abstract class AbstractHttpTest
server.stop();
}
- protected SimpleHttpParser.TestHttpResponse executeRequest() throws URISyntaxException, IOException
+ protected SimpleHttpResponse executeRequest() throws URISyntaxException, IOException
{
Socket socket = new Socket("localhost", connector.getLocalPort());
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
@@ -81,20 +81,25 @@ public abstract class AbstractHttpTest
writer.println("\r\n");
writer.flush();
- return httpParser.readResponse(reader);
+ SimpleHttpResponse response = httpParser.readResponse(reader);
+ if ("HTTP/1.1".equals(httpVersion) && response.getHeaders().get("content-length") == null && response
+ .getHeaders().get("transfer-encoding") == null)
+ assertThat("If HTTP/1.1 response doesn't contain transfer-encoding or content-length headers, " +
+ "it should contain connection:close", response.getHeaders().get("connection"), is("close"));
+ return response;
}
- protected void assertResponseBody(SimpleHttpParser.TestHttpResponse response, String expectedResponseBody)
+ protected void assertResponseBody(SimpleHttpResponse response, String expectedResponseBody)
{
assertThat("response body is" + expectedResponseBody, response.getBody(), is(expectedResponseBody));
}
- protected void assertHeader(SimpleHttpParser.TestHttpResponse response, String headerName, String expectedValue)
+ protected void assertHeader(SimpleHttpResponse response, String headerName, String expectedValue)
{
assertThat(headerName + "=" + expectedValue, response.getHeaders().get(headerName), is(expectedValue));
}
- private static class TestCommitException extends IllegalStateException
+ protected static class TestCommitException extends IllegalStateException
{
public TestCommitException()
{
@@ -118,4 +123,5 @@ public abstract class AbstractHttpTest
throw new TestCommitException();
}
}
+
}
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java
new file mode 100644
index 0000000..da54ce2
--- /dev/null
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java
@@ -0,0 +1,122 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.server;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.http.HttpVersion;
+import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+//TODO: reset buffer tests
+//TODO: add protocol specific tests for connection: close and/or chunking
+@RunWith(value = Parameterized.class)
+public class HttpManyWaysToAsyncCommitBadBehaviourTest extends AbstractHttpTest
+{
+ private final String CONTEXT_ATTRIBUTE = getClass().getName() + ".asyncContext";
+ private boolean dispatch; // if true we dispatch, otherwise we complete
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> data()
+ {
+ Object[][] data = new Object[][]{{HttpVersion.HTTP_1_0.asString(), true}, {HttpVersion.HTTP_1_0.asString(),
+ false}, {HttpVersion.HTTP_1_1.asString(), true}, {HttpVersion.HTTP_1_1.asString(), false}};
+ return Arrays.asList(data);
+ }
+
+ public HttpManyWaysToAsyncCommitBadBehaviourTest(String httpVersion, boolean dispatch)
+ {
+ super(httpVersion);
+ this.httpVersion = httpVersion;
+ this.dispatch = dispatch;
+ }
+
+ @Test
+ public void testHandlerSetsHandledAndWritesSomeContent() throws Exception
+ {
+ server.setHandler(new SetHandledWriteSomeDataHandler(false));
+ server.start();
+
+ SimpleHttpResponse response = executeRequest();
+
+ assertThat("response code is 500", response.getCode(), is("500"));
+ }
+
+ private class SetHandledWriteSomeDataHandler extends ThrowExceptionOnDemandHandler
+ {
+ private SetHandledWriteSomeDataHandler(boolean throwException)
+ {
+ super(throwException);
+ }
+
+ @Override
+ public void handle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ final CyclicBarrier resumeBarrier = new CyclicBarrier(1);
+ if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
+ {
+ final AsyncContext asyncContext = baseRequest.startAsync();
+ new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ asyncContext.getResponse().getWriter().write("foobar");
+ if (dispatch)
+ asyncContext.dispatch();
+ else
+ asyncContext.complete();
+ resumeBarrier.await(5, TimeUnit.SECONDS);
+ }
+ catch (IOException | TimeoutException | InterruptedException | BrokenBarrierException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }).run();
+ }
+ try
+ {
+ resumeBarrier.await(5, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException | BrokenBarrierException | TimeoutException e)
+ {
+ e.printStackTrace();
+ }
+ throw new TestCommitException();
+ }
+ }
+}
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java
index 234d7f8..24671c6 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java
@@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpVersion;
-import org.eclipse.jetty.server.util.SimpleHttpParser;
+import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -66,7 +66,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new DoesNotSetHandledHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 404", response.getCode(), is("404"));
}
@@ -77,7 +77,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new DoesNotSetHandledHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 500", response.getCode(), is("500"));
}
@@ -120,7 +120,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new OnlySetHandledHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertHeader(response, "content-length", "0");
@@ -132,7 +132,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new OnlySetHandledHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 500", response.getCode(), is("500"));
}
@@ -177,7 +177,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new SetHandledWriteSomeDataHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertHeader(response, "content-length", "6");
@@ -189,7 +189,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new SetHandledWriteSomeDataHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 500", response.getCode(), is("500"));
}
@@ -241,7 +241,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new ExplicitFlushHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
@@ -255,7 +255,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new ExplicitFlushHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -311,7 +311,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new SetHandledAndFlushWithoutContentHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -324,7 +324,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new SetHandledAndFlushWithoutContentHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -378,7 +378,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new WriteFlushWriteMoreHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -391,7 +391,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new WriteFlushWriteMoreHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -448,7 +448,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new OverflowHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertResponseBody(response, "foobar");
@@ -461,7 +461,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new OverflowHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
// response not committed when we throw, so 500 expected
assertThat("response code is 500", response.getCode(), is("500"));
@@ -516,7 +516,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new SetContentLengthAndWriteThatAmountOfBytesHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertThat("response body is foo", response.getBody(), is("foo"));
@@ -529,7 +529,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new SetContentLengthAndWriteThatAmountOfBytesHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
//TODO: should we expect 500 here?
assertThat("response code is 200", response.getCode(), is("200"));
@@ -586,7 +586,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new SetContentLengthAndWriteMoreBytesHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
// jetty truncates the body when content-length is reached.! This is correct and desired behaviour?
@@ -600,7 +600,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new SetContentLengthAndWriteMoreBytesHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
// TODO: we throw before response is committed. should we expect 500?
assertThat("response code is 200", response.getCode(), is("200"));
@@ -657,7 +657,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new WriteAndSetContentLengthHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
//TODO: jetty ignores setContentLength and sends transfer-encoding header. Correct?
@@ -669,7 +669,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new WriteAndSetContentLengthHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
}
@@ -724,7 +724,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new WriteAndSetContentLengthTooSmallHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertResponseBody(response, "foobar");
@@ -739,7 +739,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
server.setHandler(new WriteAndSetContentLengthTooSmallHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat(response.getCode(), is("500"));
}
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java
index 476da5d..9c5778f 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java
@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpVersion;
-import org.eclipse.jetty.server.util.SimpleHttpParser;
+import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,7 +58,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new DoesNotSetHandledHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 404", response.getCode(), is("404"));
}
@@ -69,7 +69,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new DoesNotSetHandledHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 500", response.getCode(), is("500"));
}
@@ -95,7 +95,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new OnlySetHandledHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertHeader(response, "content-length", "0");
@@ -107,7 +107,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new OnlySetHandledHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 500", response.getCode(), is("500"));
}
@@ -134,7 +134,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new SetHandledWriteSomeDataHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertHeader(response, "content-length", "6");
@@ -146,7 +146,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new SetHandledWriteSomeDataHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 500", response.getCode(), is("500"));
}
@@ -173,7 +173,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new ExplicitFlushHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
@@ -187,7 +187,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new ExplicitFlushHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -217,7 +217,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new SetHandledAndFlushWithoutContentHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -230,7 +230,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new SetHandledAndFlushWithoutContentHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -259,7 +259,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new WriteFlushWriteMoreHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -272,7 +272,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new WriteFlushWriteMoreHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
if ("HTTP/1.1".equals(httpVersion))
@@ -303,7 +303,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new OverflowHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertResponseBody(response, "foobar");
@@ -316,7 +316,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new OverflowHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
// response not committed when we throw, so 500 expected
assertThat("response code is 500", response.getCode(), is("500"));
@@ -345,7 +345,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new SetContentLengthAndWriteThatAmountOfBytesHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertThat("response body is foo", response.getBody(), is("foo"));
@@ -359,7 +359,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new SetContentLengthAndWriteThatAmountOfBytesHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
//TODO: should we expect 500 here?
assertThat("response code is 200", response.getCode(), is("200"));
@@ -390,7 +390,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new SetContentLengthAndWriteMoreBytesHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
// jetty truncates the body when content-length is reached.! This is correct and desired behaviour?
@@ -404,7 +404,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new SetContentLengthAndWriteMoreBytesHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
// TODO: we throw before response is committed. should we expect 500?
assertThat("response code is 200", response.getCode(), is("200"));
@@ -435,7 +435,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new WriteAndSetContentLengthHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
//TODO: jetty ignores setContentLength and sends transfer-encoding header. Correct?
@@ -447,7 +447,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new WriteAndSetContentLengthHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
}
@@ -476,7 +476,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new WriteAndSetContentLengthTooSmallHandler(false));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat("response code is 200", response.getCode(), is("200"));
assertResponseBody(response, "foobar");
@@ -491,7 +491,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.setHandler(new WriteAndSetContentLengthTooSmallHandler(true));
server.start();
- SimpleHttpParser.TestHttpResponse response = executeRequest();
+ SimpleHttpResponse response = executeRequest();
assertThat(response.getCode(), is("500"));
}
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/util/SimpleHttpParser.java b/jetty-server/src/test/java/org/eclipse/jetty/server/util/SimpleHttpParser.java
deleted file mode 100644
index 59af660..0000000
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/util/SimpleHttpParser.java
+++ /dev/null
@@ -1,201 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.server.util;
-
-import java.io.BufferedReader;
-import java.io.EOFException;
-import java.io.IOException;
-import java.net.SocketTimeoutException;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public class SimpleHttpParser
-{
- final String httpVersion;
-
- public SimpleHttpParser(String httpVersion)
- {
- this.httpVersion = httpVersion;
- }
-
- public TestHttpResponse readResponse(BufferedReader reader) throws IOException
- {
- // Simplified parser for HTTP responses
- String line = reader.readLine();
- if (line == null)
- throw new EOFException();
- Matcher responseLine = Pattern.compile("HTTP/1.1" + "\\s+(\\d+)").matcher(line);
- assertThat("http version is 1.1", responseLine.lookingAt(), is(true));
- String code = responseLine.group(1);
-
- Map<String, String> headers = new LinkedHashMap<>();
- while ((line = reader.readLine()) != null)
- {
- if (line.trim().length() == 0)
- break;
-
- parseHeader(line, headers);
- }
-
- StringBuilder body;
- if (headers.containsKey("content-length"))
- {
- body = parseContentLengthDelimitedBody(reader, headers);
- }
- else if ("chunked".equals(headers.get("transfer-encoding")))
- {
- body = parseChunkedBody(reader);
- }
- else
- {
- body = parseEOFDelimitedBody(reader, headers);
- }
-
- return new TestHttpResponse(code, headers, body.toString().trim());
- }
-
- private void parseHeader(String line, Map<String, String> headers)
- {
- Matcher header = Pattern.compile("([^:]+):\\s*(.*)").matcher(line);
- assertTrue(header.lookingAt());
- String headerName = header.group(1);
- String headerValue = header.group(2);
- headers.put(headerName.toLowerCase(), headerValue.toLowerCase());
- }
-
- private StringBuilder parseContentLengthDelimitedBody(BufferedReader reader, Map<String, String> headers) throws IOException
- {
- StringBuilder body;
- int readLen = 0;
- int length = Integer.parseInt(headers.get("content-length"));
- body = new StringBuilder(length);
- try
- {
- //TODO: UTF-8 reader from joakim
- for (int i = 0; i < length; ++i)
- {
- char c = (char)reader.read();
- body.append(c);
- readLen++;
- }
-
- }
- catch (SocketTimeoutException e)
- {
- System.err.printf("Read %,d bytes (out of an expected %,d bytes)%n", readLen, length);
- throw e;
- }
- return body;
- }
-
- private StringBuilder parseChunkedBody(BufferedReader reader) throws IOException
- {
- StringBuilder body;
- String line;
- body = new StringBuilder(64 * 1024);
- while ((line = reader.readLine()) != null)
- {
- if ("0".equals(line))
- {
- line = reader.readLine();
- assertThat("There's no more content after as 0 indicated the final chunk", line, is(""));
- break;
- }
-
- int length = Integer.parseInt(line, 16);
- //TODO: UTF-8 reader from joakim
- for (int i = 0; i < length; ++i)
- {
- char c = (char)reader.read();
- body.append(c);
- }
- reader.readLine();
- // assertThat("chunk is followed by an empty line", line, is("")); //TODO: is this right? - NO. Don't
- // think you can really do chunks with read line generally, but maybe for this test is OK.
- }
- return body;
- }
-
- private StringBuilder parseEOFDelimitedBody(BufferedReader reader, Map<String, String> headers) throws IOException
- {
- StringBuilder body;
- if ("HTTP/1.1".equals(httpVersion))
- assertThat("if no content-length or transfer-encoding header is set, " +
- "connection: close header must be set", headers.get("connection"),
- is("close"));
-
- // read until EOF
- body = new StringBuilder();
- while (true)
- {
- //TODO: UTF-8 reader from joakim
- int read = reader.read();
- if (read == -1)
- break;
- char c = (char)read;
- body.append(c);
- }
- return body;
- }
-
- public static class TestHttpResponse
- {
- private final String code;
- private final Map<String, String> headers;
- private final String body;
-
- public TestHttpResponse(String code, Map<String, String> headers, String body)
- {
- this.code = code;
- this.headers = headers;
- this.body = body;
- }
-
- public String getCode()
- {
- return code;
- }
-
- public Map<String, String> getHeaders()
- {
- return headers;
- }
-
- public String getBody()
- {
- return body;
- }
-
- @Override
- public String toString()
- {
- return "Response{" +
- "code='" + code + '\'' +
- ", headers=" + headers +
- ", body='" + body + '\'' +
- '}';
- }
- }
-}