use of io.undertow.server.handlers.encoding.EncodingHandler in project undertow by undertow-io.
the class LoadBalancingProxyTestCase method setup.
@BeforeClass
public static void setup() throws URISyntaxException {
int port = DefaultServer.getHostPort("default");
server1 = Undertow.builder().addHttpListener(port + 1, DefaultServer.getHostAddress("default")).setSocketOption(Options.REUSE_ADDRESSES, true).setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, IDLE_TIMEOUT).setHandler(getRootHandler("s1", "server1")).build();
server2 = Undertow.builder().addHttpListener(port + 2, DefaultServer.getHostAddress("default")).setSocketOption(Options.REUSE_ADDRESSES, true).setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, IDLE_TIMEOUT).setHandler(getRootHandler("s2", "server2")).build();
server1.start();
server2.start();
ProxyHandler handler = new ProxyHandler(new LoadBalancingProxyClient().setConnectionsPerThread(4).addHost(new URI("http", null, DefaultServer.getHostAddress("default"), port + 1, null, null, null), "s1").addHost(new URI("http", null, DefaultServer.getHostAddress("default"), port + 2, null, null, null), "s2"), 10000, ResponseCodeHandler.HANDLE_404, false, false, 2);
DefaultServer.setRootHandler(new EncodingHandler(handler, new ContentEncodingRepository().addEncodingHandler("gzip", new GzipEncodingProvider(), 50, Predicates.truePredicate())));
}
use of io.undertow.server.handlers.encoding.EncodingHandler in project spring-boot by spring-projects.
the class UndertowServletWebServer method configurationCompressionIfNecessary.
private HttpHandler configurationCompressionIfNecessary(HttpHandler httpHandler) {
if (this.compression == null || !this.compression.getEnabled()) {
return httpHandler;
}
ContentEncodingRepository repository = new ContentEncodingRepository();
repository.addEncodingHandler("gzip", new GzipEncodingProvider(), 50, Predicates.and(getCompressionPredicates(this.compression)));
return new EncodingHandler(repository).setNext(httpHandler);
}
use of io.undertow.server.handlers.encoding.EncodingHandler in project undertow by undertow-io.
the class ServerSentEventTestCase method testProgressiveSSEWithCompression.
@Test
public void testProgressiveSSEWithCompression() throws IOException {
final AtomicReference<ServerSentEventConnection> connectionReference = new AtomicReference<>();
DecompressingHttpClient client = new DecompressingHttpClient(new TestHttpClient());
try {
DefaultServer.setRootHandler(new EncodingHandler(new ContentEncodingRepository().addEncodingHandler("deflate", new DeflateEncodingProvider(), 50)).setNext(new ServerSentEventHandler(new ServerSentEventConnectionCallback() {
@Override
public void connected(ServerSentEventConnection connection, String lastEventId) {
connectionReference.set(connection);
connection.send("msg 1", new ServerSentEventConnection.EventCallback() {
@Override
public void done(ServerSentEventConnection connection, String data, String event, String id) {
}
@Override
public void failed(ServerSentEventConnection connection, String data, String event, String id, IOException e) {
e.printStackTrace();
IoUtils.safeClose(connection);
}
});
}
})));
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
InputStream stream = result.getEntity().getContent();
assertData(stream, "data:msg 1\n\n");
connectionReference.get().send("msg 2");
assertData(stream, "data:msg 2\n\n");
connectionReference.get().close();
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.server.handlers.encoding.EncodingHandler in project wildfly by wildfly.
the class GzipFilter method createHttpHandler.
@Override
public HttpHandler createHttpHandler(final Predicate predicate, ModelNode model, HttpHandler next) {
EncodingHandler encodingHandler = new EncodingHandler(new ContentEncodingRepository().addEncodingHandler("gzip", new GzipEncodingProvider(), 50, predicate != null ? predicate : Predicates.truePredicate()));
encodingHandler.setNext(next);
return encodingHandler;
}
Aggregations