All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.muserver.ServerSettings Maven / Gradle / Ivy

The newest version!
package io.muserver;

import java.util.List;
import java.util.Set;

class ServerSettings {
    final long minimumGzipSize;
    final int maxHeadersSize;
    final long requestReadTimeoutMillis;
    final long maxRequestSize;
    final int maxUrlSize;
    final boolean gzipEnabled;
    final Set mimeTypesToGzip;
    final List rateLimiters;

    ServerSettings(long minimumGzipSize, int maxHeadersSize, long requestReadTimeoutMillis, long maxRequestSize, int maxUrlSize, boolean gzipEnabled, Set mimeTypesToGzip, List rateLimiters) {
        this.minimumGzipSize = minimumGzipSize;
        this.maxHeadersSize = maxHeadersSize;
        this.requestReadTimeoutMillis = requestReadTimeoutMillis;
        this.maxRequestSize = maxRequestSize;
        this.maxUrlSize = maxUrlSize;
        this.gzipEnabled = gzipEnabled;
        this.mimeTypesToGzip = mimeTypesToGzip;
        this.rateLimiters = rateLimiters;
    }

    boolean shouldCompress(String declaredLength, String contentType) {
        if (!gzipEnabled) {
            return false;
        }
        if (declaredLength != null && Long.parseLong(declaredLength) <= minimumGzipSize) {
            return false;
        }
        if (contentType == null) {
            return false;
        }
        int i = contentType.indexOf(";");
        if (i > -1) {
            contentType = contentType.substring(0, i);
        }
        return mimeTypesToGzip.contains(contentType.trim());
    }

    public boolean block(MuRequest request) {
        boolean allowed = true;
        if (rateLimiters != null) {
            for (RateLimiterImpl limiter : rateLimiters) {
                allowed &= limiter.record(request);
            }
        }
        return !allowed;
    }

    @Override
    public String toString() {
        return "ServerSettings{" +
            "minimumGzipSize=" + minimumGzipSize +
            ", maxHeadersSize=" + maxHeadersSize +
            ", requestReadTimeoutMillis=" + requestReadTimeoutMillis +
            ", maxRequestSize=" + maxRequestSize +
            ", maxUrlSize=" + maxUrlSize +
            ", gzipEnabled=" + gzipEnabled +
            ", rateLimiters=" + rateLimiters +
            '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy