@Override public HttpHandler wrap(HttpHandler handler) { return new EncodingHandler(handler, new ContentEncodingRepository() .addEncodingHandler("gzip", new GzipEncodingProvider(), 100) .addEncodingHandler("deflate", new DeflateEncodingProvider(), 10)); } };
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || !exchange.isResponseChannelAvailable()) { next.handleRequest(exchange); } else if (encodings.isNoEncodingsAllowed()) { noEncodingHandler.handleRequest(exchange); } else { exchange.addResponseWrapper(encodings); exchange.putAttachment(AllowedContentEncodings.ATTACHMENT_KEY, encodings); next.handleRequest(exchange); } }
public synchronized ContentEncodingRepository addEncodingHandler(final String encoding, final ContentEncodingProvider encoder, int priority) { addEncodingHandler(encoding, encoder, priority, Predicates.truePredicate()); return this; }
PathHandler path = Handlers.path(Handlers.redirect("/")) .addPrefixPath("/", manager.start()); final EncodingHandler handler = new EncodingHandler(new ContentEncodingRepository() .addEncodingHandler("gzip", new GzipEncodingProvider(), 50, Predicates.parse("max-content-size[5]"))) .setNext(path); // ... Undertow server = builder.setHandler(handler).build();
public synchronized ContentEncodingRepository addEncodingHandler(final String encoding, final ContentEncodingProvider encoder, int priority) { addEncodingHandler(encoding, encoder, priority, Predicates.truePredicate()); return this; }
public ResponseEncodeHandler() { contentEncodingRepository = new ContentEncodingRepository(); List<String> encoders = config.getEncoders(); for(int i = 0; i < encoders.size(); i++) { String encoder = encoders.get(i); if(Constants.ENCODE_GZIP.equals(encoder)) { contentEncodingRepository.addEncodingHandler(encoder, new GzipEncodingProvider(), 100); } else if(Constants.ENCODE_DEFLATE.equals(encoder)) { contentEncodingRepository.addEncodingHandler(encoder, new DeflateEncodingProvider(), 10); } else { throw new RuntimeException("Invalid encoder " + encoder + " for ResponseEncodeHandler."); } } }
public synchronized ContentEncodingRepository addEncodingHandler(final String encoding, final ContentEncodingProvider encoder, int priority) { addEncodingHandler(encoding, encoder, priority, Predicates.truePredicate()); return this; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || !exchange.isResponseChannelAvailable()) { Handler.next(exchange, next); } else if (encodings.isNoEncodingsAllowed()) { setExchangeStatus(exchange, NO_ENCODING_HANDLER); return; } else { exchange.addResponseWrapper(encodings); exchange.putAttachment(AllowedContentEncodings.ATTACHMENT_KEY, encodings); Handler.next(exchange, next); } } }
@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; }
return null; AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || encodings.isNoEncodingsAllowed()) { return null;
/** * Optionally wrap the given {@link HttpHandler} for HTTP compression support. * @param compression the HTTP compression configuration * @param httpHandler the HTTP handler to wrap * @return the wrapped HTTP handler if compression is enabled, or the handler itself */ public static HttpHandler configureCompression(Compression compression, HttpHandler httpHandler) { if (compression == null || !compression.getEnabled()) { return httpHandler; } ContentEncodingRepository repository = new ContentEncodingRepository(); repository.addEncodingHandler("gzip", new GzipEncodingProvider(), 50, Predicates.and(getCompressionPredicates(compression))); return new EncodingHandler(repository).setNext(httpHandler); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || !exchange.isResponseChannelAvailable()) { next.handleRequest(exchange); } else if (encodings.isNoEncodingsAllowed()) { noEncodingHandler.handleRequest(exchange); } else { exchange.addResponseWrapper(encodings); exchange.putAttachment(AllowedContentEncodings.ATTACHMENT_KEY, encodings); next.handleRequest(exchange); } }
public HttpHandler createHttpHandler() { PathHandler pathHandler = new PathHandler(); pathHandler.addPrefixPath("/v1/invoke", new AllowedMethodsHandler(new HttpInvocationHandler(association, executorService, localTransactionContext, cancellationFlags), Methods.POST)) .addPrefixPath("/v1/open", new AllowedMethodsHandler(new HttpSessionOpenHandler(association, executorService, localTransactionContext), Methods.POST)) .addPrefixPath("/v1/cancel", new AllowedMethodsHandler(new HttpCancelHandler(association, executorService, localTransactionContext, cancellationFlags), Methods.DELETE)); EncodingHandler encodingHandler = new EncodingHandler(pathHandler, new ContentEncodingRepository().addEncodingHandler(Headers.GZIP.toString(), new GzipEncodingProvider(), 1)); RequestEncodingHandler requestEncodingHandler = new RequestEncodingHandler(encodingHandler); requestEncodingHandler.addEncoding(Headers.GZIP.toString(), GzipStreamSourceConduit.WRAPPER); return requestEncodingHandler; }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || !exchange.isResponseChannelAvailable()) { next.handleRequest(exchange); } else if (encodings.isNoEncodingsAllowed()) { noEncodingHandler.handleRequest(exchange); } else { exchange.addResponseWrapper(encodings); exchange.putAttachment(AllowedContentEncodings.ATTACHMENT_KEY, encodings); next.handleRequest(exchange); } }
/** * Creates a new instance of GzipEncodingHandler * * @param next * @param forceCompression if true requests without gzip encoding in * Accept-Encoding header will be rejected */ public GzipEncodingHandler(HttpHandler next, boolean forceCompression) { super(next, new ContentEncodingRepository().addEncodingHandler("gzip", new GzipEncodingProvider(), 50)); this.forceCompression = forceCompression; }
return null; AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || encodings.isNoEncodingsAllowed()) { return null;
@Override public HttpHandler wrap(HttpHandler handler) { return new EncodingHandler(handler, new ContentEncodingRepository() .addEncodingHandler("gzip", new GzipEncodingProvider(), 100) .addEncodingHandler("deflate", new DeflateEncodingProvider(), 10)); } };
return null; AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || encodings.isNoEncodingsAllowed()) { return null;
@Override public HttpHandler wrap(HttpHandler handler) { return new EncodingHandler(handler, new ContentEncodingRepository() .addEncodingHandler("gzip", new GzipEncodingProvider(), 100) .addEncodingHandler("deflate", new DeflateEncodingProvider(), 10)); } };
@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; }