Search in sources :

Example 1 with DefaultResourceSupplier

use of io.undertow.server.handlers.resource.DefaultResourceSupplier in project undertow by undertow-io.

the class DefaultServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ServletContextImpl sc = (ServletContextImpl) config.getServletContext();
    this.deployment = sc.getDeployment();
    DefaultServletConfig defaultServletConfig = deployment.getDeploymentInfo().getDefaultServletConfig();
    if (defaultServletConfig != null) {
        defaultAllowed = defaultServletConfig.isDefaultAllowed();
        allowed = new HashSet<>();
        if (defaultServletConfig.getAllowed() != null) {
            allowed.addAll(defaultServletConfig.getAllowed());
        }
        disallowed = new HashSet<>();
        if (defaultServletConfig.getDisallowed() != null) {
            disallowed.addAll(defaultServletConfig.getDisallowed());
        }
    }
    if (config.getInitParameter(DEFAULT_ALLOWED) != null) {
        defaultAllowed = Boolean.parseBoolean(config.getInitParameter(DEFAULT_ALLOWED));
    }
    if (config.getInitParameter(ALLOWED_EXTENSIONS) != null) {
        String extensions = config.getInitParameter(ALLOWED_EXTENSIONS);
        allowed = new HashSet<>(Arrays.asList(extensions.split(",")));
    }
    if (config.getInitParameter(DISALLOWED_EXTENSIONS) != null) {
        String extensions = config.getInitParameter(DISALLOWED_EXTENSIONS);
        disallowed = new HashSet<>(Arrays.asList(extensions.split(",")));
    }
    if (config.getInitParameter(RESOLVE_AGAINST_CONTEXT_ROOT) != null) {
        resolveAgainstContextRoot = Boolean.parseBoolean(config.getInitParameter(RESOLVE_AGAINST_CONTEXT_ROOT));
    }
    if (config.getInitParameter(ALLOW_POST) != null) {
        allowPost = Boolean.parseBoolean(config.getInitParameter(ALLOW_POST));
    }
    if (deployment.getDeploymentInfo().getPreCompressedResources().isEmpty()) {
        this.resourceSupplier = new DefaultResourceSupplier(deployment.getDeploymentInfo().getResourceManager());
    } else {
        PreCompressedResourceSupplier preCompressedResourceSupplier = new PreCompressedResourceSupplier(deployment.getDeploymentInfo().getResourceManager());
        for (Map.Entry<String, String> entry : deployment.getDeploymentInfo().getPreCompressedResources().entrySet()) {
            preCompressedResourceSupplier.addEncoding(entry.getKey(), entry.getValue());
        }
        this.resourceSupplier = preCompressedResourceSupplier;
    }
    String listings = config.getInitParameter(DIRECTORY_LISTING);
    if (Boolean.valueOf(listings)) {
        this.directoryListingEnabled = true;
    }
}
Also used : ServletContextImpl(io.undertow.servlet.spec.ServletContextImpl) DefaultServletConfig(io.undertow.servlet.api.DefaultServletConfig) DefaultResourceSupplier(io.undertow.server.handlers.resource.DefaultResourceSupplier) PreCompressedResourceSupplier(io.undertow.server.handlers.resource.PreCompressedResourceSupplier) Map(java.util.Map)

Aggregations

DefaultResourceSupplier (io.undertow.server.handlers.resource.DefaultResourceSupplier)1 PreCompressedResourceSupplier (io.undertow.server.handlers.resource.PreCompressedResourceSupplier)1 DefaultServletConfig (io.undertow.servlet.api.DefaultServletConfig)1 ServletContextImpl (io.undertow.servlet.spec.ServletContextImpl)1 Map (java.util.Map)1