Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.undertow.server.handlers.encoding;
 
 import java.util.List;
 
An attachment that provides information about the current content encoding that will be chosen for the response

Author(s):
Stuart Douglas
    public static final AttachmentKey<AllowedContentEncodingsATTACHMENT_KEY = AttachmentKey.create(AllowedContentEncodings.class);
    private final HttpServerExchange exchange;
    private final List<EncodingMappingencodings;
    public AllowedContentEncodings(final HttpServerExchange exchangefinal List<EncodingMappingencodings) {
        this. = exchange;
        this. = encodings;
    }

    

Returns:
The content encoding that will be set, given the current state of the HttpServerExchange
    public String getCurrentContentEncoding() {
        for (EncodingMapping encoding : ) {
            if (encoding.getAllowed() == null || encoding.getAllowed().resolve()) {
                return encoding.getName();
            }
        }
        return ..toString();
    }
    public EncodingMapping getEncoding() {
        for (EncodingMapping encoding : ) {
            if (encoding.getAllowed() == null || encoding.getAllowed().resolve()) {
                return encoding;
            }
        }
        return null;
    }
    public boolean isIdentity() {
    }

    
If the list of allowed encodings was empty then it means that no encodings were allowed, and identity was explicitly prohibited with a q value of 0.
    public boolean isNoEncodingsAllowed() {
        return .isEmpty();
    }
    @Override
    public StreamSinkConduit wrap(final ConduitFactory<StreamSinkConduitfactoryfinal HttpServerExchange exchange) {
        if (exchange.getResponseHeaders().contains(.)) {
            //already encoded
            return factory.create();
        }
        //if this is a zero length response we don't want to encode
        if (exchange.getResponseContentLength() != 0
                && exchange.getResponseCode() != 204
                && exchange.getResponseCode() != 304) {
            EncodingMapping encoding = getEncoding();
            if (encoding != null) {
                exchange.getResponseHeaders().put(.encoding.getName());
                if (exchange.getRequestMethod().equals(.)) {
                    //we don't create an actual encoder for HEAD requests, but we set the header
                    return factory.create();
                } else {
                    return encoding.getEncoding().getResponseWrapper().wrap(factoryexchange);
                }
            }
        }
        return factory.create();
    }
New to GrepCode? Check out our FAQ X