Skip to content

Commit

Permalink
Issue #4936 - Updating LargeHeaderTest to use ServerConnector
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <[email protected]>
  • Loading branch information
joakime committed Jun 3, 2020
1 parent 33153b9 commit 9a5dd78
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package org.eclipse.jetty.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.net.Socket;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -33,18 +35,21 @@
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class LargeHeaderTest
{
private Server server;
private LocalConnector connector;

@BeforeEach
public void setup() throws Exception
Expand All @@ -54,7 +59,8 @@ public void setup() throws Exception
HttpConfiguration config = new HttpConfiguration();
HttpConnectionFactory http = new HttpConnectionFactory(config);

connector = new LocalConnector(server, http, null);
ServerConnector connector = new ServerConnector(server, http);
connector.setPort(0);
connector.setIdleTimeout(5000);
server.addConnector(connector);

Expand All @@ -67,7 +73,7 @@ public void setup() throws Exception
{
byte[] bytes = new byte[8 * 1024];
Arrays.fill(bytes, (byte)'X');
largeHeaderValue = "LargeHeaderOver8k-" + new String(bytes, StandardCharsets.ISO_8859_1) + "_Z_";
largeHeaderValue = "LargeHeaderOver8k-" + new String(bytes, UTF_8) + "_Z_";
}

@Override
Expand All @@ -94,24 +100,34 @@ public void teardown()
@Test
public void testLargeHeader() throws Exception
{
final Logger CLIENTLOG = Log.getLogger(LargeHeaderTest.class).getLogger(".client");
ExecutorService executorService = Executors.newFixedThreadPool(8);

int localPort = server.getURI().getPort();
String rawRequest = "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Host: localhost:" + localPort + "\r\n" +
"\r\n";

for (int i = 0; i < 500; ++i)
{
executorService.submit(() ->
{
try
try (Socket client = new Socket("localhost", localPort);
OutputStream output = client.getOutputStream();
InputStream input = client.getInputStream())
{
HttpTester.Response response = HttpTester.parseResponse(connector.getResponse(rawRequest));
output.write(rawRequest.getBytes(UTF_8));
output.flush();

String rawResponse = IO.toString(input, UTF_8);

CLIENTLOG.info("rawResponse[{}]=[{}]", rawResponse.length(), rawResponse);
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
assertThat(response.getStatus(), is(500));
}
catch (Throwable t)
{
t.printStackTrace();
CLIENTLOG.warn("Client Issue", t);
}
});
}
Expand Down

0 comments on commit 9a5dd78

Please sign in to comment.