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

org.zodiac.netty.http.headers.CacheControlHeader Maven / Gradle / Ivy

package org.zodiac.netty.http.headers;

import java.util.Objects;

import org.zodiac.commons.http.entities.CacheControl;

import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.util.AsciiString;

final class CacheControlHeader extends AbstractHeader {

    private static final AsciiString PRIVATE_NO_CACHE_NO_STORE = AsciiString.of(CacheControl.PRIVATE_NO_CACHE_NO_STORE.toString());
    private static final AsciiString PUBLIC = AsciiString.of(CacheControl.PUBLIC.toString());
    private static final AsciiString PUBLIC_MUST_REVALIDATE = AsciiString.of(CacheControl.PUBLIC_MUST_REVALIDATE.toString());
    private static final AsciiString PUBLIC_MUST_REVALIDATE_MAX_AGE_1_DAY = AsciiString.of(CacheControl.PUBLIC_MUST_REVALIDATE_MAX_AGE_1_DAY.toString());
    private static final AsciiString PUBLIC_MUST_REVALIDATE_MAX_AGE_TEN_YEARS = AsciiString.of(CacheControl.PUBLIC_MAX_AGE_TEN_YEARS.toString());
    private static final AsciiString PUBLIC_MAX_AGE_TEN_YEARS = AsciiString.of(CacheControl.PUBLIC_MUST_REVALIDATE_MAX_AGE_TEN_YEARS.toString());
    private static final AsciiString PUBLIC_IMMUTABLE = AsciiString.of(CacheControl.PUBLIC_IMMUTABLE.toString());

    CacheControlHeader() {
        super(CacheControl.class, HttpHeaderNames.CACHE_CONTROL);
    }

    @Override
    public String toString(CacheControl value) {
        Objects.requireNonNull(value, "value");
        return value.toString();
    }

    @Override
    public CharSequence toCharSequence(CacheControl value) {
        /*Avoid parsing common values*/
        if (value == CacheControl.PRIVATE_NO_CACHE_NO_STORE) {
            return PRIVATE_NO_CACHE_NO_STORE;
        } else if (value == CacheControl.PUBLIC) {
            return PUBLIC;
        } else if (value == CacheControl.PUBLIC_MUST_REVALIDATE) {
            return PUBLIC_MUST_REVALIDATE;
        } else if (value == CacheControl.PUBLIC_MUST_REVALIDATE_MAX_AGE_1_DAY) {
            return PUBLIC_MUST_REVALIDATE_MAX_AGE_1_DAY;
        } else if (value == CacheControl.PUBLIC_MAX_AGE_TEN_YEARS) {
            return PUBLIC_MAX_AGE_TEN_YEARS;
        } else if (value == CacheControl.PUBLIC_MUST_REVALIDATE_MAX_AGE_TEN_YEARS) {
            return PUBLIC_MUST_REVALIDATE_MAX_AGE_TEN_YEARS;
        } else if (value == CacheControl.PUBLIC_IMMUTABLE) {
            return PUBLIC_IMMUTABLE;
        }
        return toString(value);
    }

    @Override
    public CacheControl toValue(CharSequence value) {
        Objects.requireNonNull(value, "value");
        return CacheControl.fromString(value);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy