diff --git a/jetty-proxy/pom.xml b/jetty-proxy/pom.xml
index 260dba6be68..4220a83ef5e 100644
--- a/jetty-proxy/pom.xml
+++ b/jetty-proxy/pom.xml
@@ -51,6 +51,13 @@
${project.version}
test
+
+ org.eclipse.jetty
+ jetty-http
+ ${project.version}
+ tests
+ test
+
org.eclipse.jetty.toolchain
jetty-test-helper
diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java
index 4abce432c2c..44daa67ae9b 100644
--- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java
+++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java
@@ -364,6 +364,7 @@ public class ConnectHandler extends HandlerWrapper
try
{
response.setStatus(statusCode);
+ response.setContentLength(0);
if (statusCode != HttpServletResponse.SC_OK)
response.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
response.getOutputStream().close();
diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AbstractConnectHandlerTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AbstractConnectHandlerTest.java
index 215926ef740..5e72b33fd5e 100644
--- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AbstractConnectHandlerTest.java
+++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AbstractConnectHandlerTest.java
@@ -18,24 +18,25 @@
package org.eclipse.jetty.proxy;
-import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
import java.net.Socket;
-import org.eclipse.jetty.server.Connector;
-import org.eclipse.jetty.server.NetworkConnector;
+import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.toolchain.test.http.SimpleHttpParser;
-import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
+import org.eclipse.jetty.toolchain.test.TestTracker;
import org.junit.After;
+import org.junit.Rule;
public abstract class AbstractConnectHandlerTest
{
+ @Rule
+ public final TestTracker tracker = new TestTracker();
protected Server server;
protected ServerConnector serverConnector;
protected Server proxy;
- protected Connector proxyConnector;
+ protected ServerConnector proxyConnector;
protected ConnectHandler connectHandler;
protected void prepareProxy() throws Exception
@@ -65,14 +66,15 @@ public abstract class AbstractConnectHandlerTest
proxy.stop();
}
- protected SimpleHttpResponse readResponse(BufferedReader reader) throws IOException
+ protected HttpTester.Response readResponse(InputStream inputStream) throws IOException
{
- return new SimpleHttpParser().readResponse(reader);
+ HttpTester.Input input = HttpTester.from(inputStream);
+ return HttpTester.parseResponse(input);
}
protected Socket newSocket() throws IOException
{
- Socket socket = new Socket("localhost", ((NetworkConnector)proxyConnector).getLocalPort());
+ Socket socket = new Socket("localhost", proxyConnector.getLocalPort());
socket.setSoTimeout(5000);
return socket;
}
diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java
index a3379793439..126b9715941 100644
--- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java
+++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java
@@ -18,11 +18,9 @@
package org.eclipse.jetty.proxy;
-import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
@@ -35,12 +33,13 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jetty.http.HttpStatus;
+import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
-import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.Assert;
import org.junit.Before;
@@ -77,23 +76,18 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
-
- // Be sure the buffered input does not have anything buffered
- Assert.assertFalse(input.ready());
+ HttpTester.Response response = readResponse(socket.getInputStream());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
// Upgrade the socket to SSL
try (SSLSocket sslSocket = wrapSocket(socket))
{
output = sslSocket.getOutputStream();
- input = new BufferedReader(new InputStreamReader(sslSocket.getInputStream()));
request =
"GET /echo HTTP/1.1\r\n" +
@@ -102,9 +96,9 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
- response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ response = readResponse(sslSocket.getInputStream());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
}
@@ -120,23 +114,18 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
-
- // Be sure the buffered input does not have anything buffered
- Assert.assertFalse(input.ready());
+ HttpTester.Response response = readResponse(socket.getInputStream());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
// Upgrade the socket to SSL
try (SSLSocket sslSocket = wrapSocket(socket))
{
output = sslSocket.getOutputStream();
- input = new BufferedReader(new InputStreamReader(sslSocket.getInputStream()));
for (int i = 0; i < 10; ++i)
{
@@ -149,9 +138,9 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
- response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("POST /echo?param=" + i + "\r\nHELLO", response.getBody());
+ response = readResponse(sslSocket.getInputStream());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("POST /echo?param=" + i + "\r\nHELLO", response.getContent());
}
}
}
@@ -187,10 +176,14 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
while ((read = input.read()) >= 0)
baos.write(read);
baos.close();
+ byte[] bytes = baos.toByteArray();
ServletOutputStream output = httpResponse.getOutputStream();
- output.println(builder.toString());
- output.write(baos.toByteArray());
+ if (bytes.length == 0)
+ output.print(builder.toString());
+ else
+ output.println(builder.toString());
+ output.write(bytes);
}
else
{
diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java
index 4ef15e3e648..c1890d16eaf 100644
--- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java
+++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java
@@ -18,11 +18,9 @@
package org.eclipse.jetty.proxy;
-import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
@@ -38,12 +36,13 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jetty.http.HttpStatus;
+import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Promise;
@@ -75,14 +74,13 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(socket.getInputStream());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
}
@@ -97,14 +95,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"GET /echo" + " HTTP/1.1\r\n" +
@@ -114,8 +112,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@@ -134,14 +132,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 403 from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("403", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.FORBIDDEN_403, response.getStatus());
// Socket should be closed
Assert.assertEquals(-1, input.read());
@@ -155,14 +153,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"GET /echo" + " HTTP/1.1\r\n" +
@@ -172,8 +170,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@@ -192,14 +190,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 403 from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("403", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.FORBIDDEN_403, response.getStatus());
// Socket should be closed
Assert.assertEquals(-1, input.read());
@@ -213,14 +211,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"GET /echo" + " HTTP/1.1\r\n" +
@@ -230,8 +228,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@@ -269,15 +267,15 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 407 from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("407", response.getCode());
- Assert.assertTrue(response.getHeaders().containsKey("Proxy-Authenticate".toLowerCase(Locale.ENGLISH)));
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.PROXY_AUTHENTICATION_REQUIRED_407, response.getStatus());
+ Assert.assertTrue(response.containsKey("Proxy-Authenticate".toLowerCase(Locale.ENGLISH)));
// Socket should be closed
Assert.assertEquals(-1, input.read());
@@ -293,14 +291,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"GET /echo" + " HTTP/1.1\r\n" +
@@ -310,8 +308,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@@ -341,23 +339,18 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- Socket socket = newSocket();
- socket.setSoTimeout(30000);
- try
+ try (Socket socket = newSocket())
{
+ socket.setSoTimeout(30000);
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 500 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("Response Code", "500", response.getCode());
- }
- finally
- {
- socket.close();
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals("Response Code", HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
}
}
@@ -372,14 +365,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"GET /echo" + " HTTP/1.1\r\n" +
@@ -389,8 +382,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@@ -408,19 +401,19 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
// The pipelined request must have gone up to the server as is
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@@ -435,14 +428,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
for (int i = 0; i < 10; ++i)
{
@@ -454,8 +447,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
}
@@ -471,14 +464,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"GET /echo HTTP/1.1\r\n" +
@@ -488,8 +481,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
// Idle server is shut down
disposeServer();
@@ -510,14 +503,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"GET /close HTTP/1.1\r\n" +
@@ -542,14 +535,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"POST /echo HTTP/1.1\r\n" +
@@ -561,8 +554,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("POST /echo\r\nHELLO", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("POST /echo\r\nHELLO", response.getContent());
request = "" +
"GET /echo" + " HTTP/1.1\r\n" +
@@ -572,14 +565,21 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@Test
public void testCONNECTAndPOSTWithBigBody() throws Exception
{
+ // Use a longer idle timeout since this test
+ // may take a long time on slower machines.
+ long idleTimeout = 5 * 60 * 1000;
+ serverConnector.setIdleTimeout(idleTimeout);
+ proxyConnector.setIdleTimeout(idleTimeout);
+ connectHandler.setIdleTimeout(idleTimeout);
+
String hostPort = "localhost:" + serverConnector.getLocalPort();
String request = "" +
@@ -589,14 +589,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
StringBuilder body = new StringBuilder();
String chunk = "0123456789ABCDEF";
@@ -613,8 +613,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("POST /echo\r\n" + body, response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("POST /echo\r\n" + body, response.getContent());
}
}
@@ -674,14 +674,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
String body = "0123456789ABCDEF";
request = "" +
@@ -694,8 +694,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
output.flush();
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("POST /echo\r\n" + body, response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("POST /echo\r\n" + body, response.getContent());
}
}
@@ -713,20 +713,20 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
socket.shutdownOutput();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
// The pipelined request must have gone up to the server as is
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@@ -741,14 +741,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
try (Socket socket = newSocket())
{
OutputStream output = socket.getOutputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ InputStream input = socket.getInputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
- SimpleHttpResponse response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
+ HttpTester.Response response = readResponse(input);
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
request = "" +
"GET /echo" + " HTTP/1.1\r\n" +
@@ -760,8 +760,8 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
// The pipelined request must have gone up to the server as is
response = readResponse(input);
- Assert.assertEquals("200", response.getCode());
- Assert.assertEquals("GET /echo", response.getBody());
+ Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
+ Assert.assertEquals("GET /echo", response.getContent());
}
}
@@ -787,10 +787,14 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
while ((read = input.read()) >= 0)
baos.write(read);
baos.close();
+ byte[] bytes = baos.toByteArray();
ServletOutputStream output = httpResponse.getOutputStream();
- output.println(builder.toString());
- output.write(baos.toByteArray());
+ if (bytes.length == 0)
+ output.print(builder.toString());
+ else
+ output.println(builder.toString());
+ output.write(bytes);
break;
}
case "/close":