class SanitizerHandler implements MiddlewareHandler {

    static SanitizerConfig config;

    EncoderWrapper bodyEncoder;
    EncoderWrapper headerEncoder;
    private volatile HttpHandler next;

    public SanitizerHandler() {
        config = SanitizerConfig.load();
        bodyEncoder = new EncoderWrapper(Encoders.forName(config.getBodyEncoder()), config.getBodyAttributesToIgnore(), config.getBodyAttributesToEncode());
        headerEncoder = new EncoderWrapper(Encoders.forName(config.getHeaderEncoder()), config.getHeaderAttributesToIgnore(), config.getHeaderAttributesToEncode());
    }

    // integration test purpose only.
    @Deprecated
    public SanitizerHandler(String configName) {
        config = SanitizerConfig.load(configName);
        bodyEncoder = new EncoderWrapper(Encoders.forName(config.getBodyEncoder()), config.getBodyAttributesToIgnore(), config.getBodyAttributesToEncode());
        headerEncoder = new EncoderWrapper(Encoders.forName(config.getHeaderEncoder()), config.getHeaderAttributesToIgnore(), config.getHeaderAttributesToEncode());
    }

    @Override
    public void handleRequest(final HttpServerExchange exchange) throws Exception {<FILL_FUNCTION_BODY>}

    @Override
    public HttpHandler getNext() {
        return next;
    }

    @Override
    public MiddlewareHandler setNext(final HttpHandler next) {
        Handlers.handlerNotNull(next);
        this.next = next;
        return this;
    }

    @Override
    public boolean isEnabled() {
        return config.isEnabled();
    }

    @Override
    public void register() {
        ModuleRegistry.registerModule(SanitizerConfig.CONFIG_NAME, SanitizerHandler.class.getName(), Config.getNoneDecryptedInstance().getJsonMapConfigNoCache(SanitizerConfig.CONFIG_NAME), null);
    }

    @Override
    public void reload() {
        config = SanitizerConfig.load();
        ModuleRegistry.registerModule(SanitizerConfig.CONFIG_NAME, SanitizerHandler.class.getName(), Config.getNoneDecryptedInstance().getJsonMapConfigNoCache(SanitizerConfig.CONFIG_NAME), null);
    }

}

        if (logger.isDebugEnabled()) logger.trace("SanitizerHandler.handleRequest starts.");
        String method = exchange.getRequestMethod().toString();
        if (config.isHeaderEnabled()) {
            HeaderMap headerMap = exchange.getRequestHeaders();
            if (headerMap != null) {
                for (HeaderValues values : headerMap) {
                    if (values != null) {
                        // if ignore list exists, it will take the precedence.
                        if(config.getHeaderAttributesToIgnore() != null && config.getHeaderAttributesToIgnore().stream().anyMatch(values.getHeaderName().toString()::equalsIgnoreCase)) {
                            if(logger.isTraceEnabled()) logger.trace("Ignore header " + values.getHeaderName().toString() + " as it is in the ignore list.");
                            continue;
                        }

                        if(config.getHeaderAttributesToEncode() != null) {
                            if(config.getHeaderAttributesToEncode().stream().anyMatch(values.getHeaderName().toString()::equalsIgnoreCase)) {
                                if(logger.isTraceEnabled()) logger.trace("Encode header " + values.getHeaderName().toString() + " as it is not in the ignore list and it is in the encode list.");
                                ListIterator<String> itValues = values.listIterator();
                                while (itValues.hasNext()) {
                                    itValues.set(headerEncoder.applyEncoding(itValues.next()));
                                }
                            }
                        } else {
                            // no attributes to encode, encode everything except the ignore list.
                            if(logger.isTraceEnabled()) logger.trace("Encode header " + values.getHeaderName().toString() + " as it is not in the ignore list and the encode list is null.");
                            ListIterator<String> itValues = values.listIterator();
                            while (itValues.hasNext()) {
                                itValues.set(headerEncoder.applyEncoding(itValues.next()));
                            }
                        }
                    }
                }
            }
        }

        if (config.isBodyEnabled() && ("POST".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method) || "PATCH".equalsIgnoreCase(method))) {
            // assume that body parser is installed before this middleware and body is parsed as a map.
            // we are talking about JSON api now.
            Object body = exchange.getAttachment(AttachmentConstants.REQUEST_BODY);
            if (body != null) {
                if(body instanceof List) {
                    bodyEncoder.encodeList((List<Map<String, Object>>)body);
                } else if (body instanceof Map){
                    // assume it is a map here.
                    bodyEncoder.encodeNode((Map<String, Object>)body);
                } else {
                    // Body is not in JSON format or form data, skip...
                }
            }
        }
        if (logger.isDebugEnabled()) logger.trace("SanitizerHandler.handleRequest ends.");
        Handler.next(exchange, next);
    
<no_super_class>