use of io.undertow.server.protocol.http.HttpServerConnection in project undertow by undertow-io.
the class ChunkedRequestTrailersTestCase method setup.
@BeforeClass
public static void setup() {
final BlockingHandler blockingHandler = new BlockingHandler();
existing = DefaultServer.getUndertowOptions();
DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.ALWAYS_SET_DATE, false));
DefaultServer.setRootHandler(blockingHandler);
blockingHandler.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) {
try {
if (connection == null) {
connection = (HttpServerConnection) exchange.getConnection();
} else if (!DefaultServer.isProxy() && connection != exchange.getConnection()) {
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
final OutputStream outputStream = exchange.getOutputStream();
outputStream.write("Connection not persistent".getBytes());
outputStream.close();
return;
}
final OutputStream outputStream = exchange.getOutputStream();
final InputStream inputStream = exchange.getInputStream();
String m = HttpClientUtils.readResponse(inputStream);
Assert.assertEquals("abcdefghi", m);
HeaderMap headers = exchange.getAttachment(HttpAttachments.REQUEST_TRAILERS);
for (HeaderValues header : headers) {
for (String val : header) {
outputStream.write(header.getHeaderName().toString().getBytes());
outputStream.write(": ".getBytes());
outputStream.write(val.getBytes());
outputStream.write("\r\n".getBytes());
}
}
inputStream.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
});
}
Aggregations