Simply moving it from src/main/java to src/test/java only means that the class would move from being a runtime class to being a testing class.
Its not meant to be a runtime class for production capacity and use.
Only for testing. These don't even use the connection layer framework (which with Jetty 9.3 and http/2 will become even more important)
Now, onto the core of the problem.
The original bug is filed under the assumption that HTTP/1.1 parsing is bad/broken.
The bug is in the assumption that you use a protocol representation with HttpTester to test with.
When SPDY was introduced, it was quickly determined that the HTTP world does not revolve around HTTP the protocol, but rather HTTP the semantic. With SPDY and now HTTP/2 you have headers, and request parameters, and uris, but not the HTTP protocol. The HttpTester was changed to behave in a protocol neutral, but HTTP semantic way.
You create a Request object, give it to the tester and let the jetty internals process it / dispatch it / get the response state / headers / content, and return it to you, as an Response object.
If you have protocol specific things to test, using HttpTester and ServletTester are not the correct way to do that. Especially if you are wanting to test content encoding or behavior (such as compressed, gzip, deflate, or chunked encoding)
Finally, here's a real test of the actual in-use HTTP/1.1 protocol, showing that there is no HTTP/1.1 protocol parsing bug.
package jetty.example;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class Bug440823Test
{
@SuppressWarnings("serial")
public static class HelloServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
resp.setContentType("text/plain");
resp.getWriter().println("Hello Test");
}
}
private static Server server;
@BeforeClass
public static void startServer() throws Exception
{
server = new Server(8080);
ServletContextHandler contexts = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
contexts.addServlet(HelloServlet.class,"/*");
server.setHandler(contexts);
server.start();
}
@AfterClass
public static void stopServer() throws Exception
{
server.stop();
}
@Test
public void testRequest() throws Throwable
{
String request =
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Header1: value1\r\n" +
"Connection: close\r\n" +
"Accept-Encoding: gzip, deflated\r\n" +
"Accept: unknown\r\n" +
"\r\n";
InetAddress destAddr = InetAddress.getByName("localhost");
int port = 8080;
SocketAddress endpoint = new InetSocketAddress(destAddr,port);
try (Socket socket = new Socket())
{
socket.connect(endpoint);
try (OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream();
Reader reader = new InputStreamReader(in);
BufferedReader buf = new BufferedReader(reader))
{
// Send GET Request
System.err.print(request);
System.err.printf("Request: %,d bytes%n",request.length());
out.write(request.getBytes(StandardCharsets.ISO_8859_1));
// Get Response
String line = null;
while ((line = buf.readLine()) != null)
{
System.err.printf("[response]: %s%n",line);
}
System.err.println("[done]");
}
}
}
}