Refactored tests to use HttpTester instead of SimpleHttpParser.
This commit is contained in:
parent
2b539b6383
commit
7c0d1ea026
|
@ -51,6 +51,13 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-http</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<classifier>tests</classifier>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
|
|
|
@ -18,17 +18,16 @@
|
|||
|
||||
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.http.HttpTester;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.NetworkConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.eclipse.jetty.toolchain.test.http.SimpleHttpParser;
|
||||
import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
|
||||
|
@ -69,9 +68,10 @@ 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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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,8 +565,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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -589,14 +582,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 +606,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 +667,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 +687,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 +706,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 +734,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 +753,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 +780,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":
|
||||
|
|
Loading…
Reference in New Issue