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

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

package org.zodiac.netty.http.headers;

import java.util.Objects;

import org.zodiac.sdk.toolkit.util.lang.StrUtil;

import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.util.internal.AppendableCharSequence;

final class VaryHeader extends AbstractHeader {

    VaryHeader() {
        super(HeaderValueType[].class, HttpHeaderNames.VARY);
    }

    @Override
    public CharSequence toCharSequence(HeaderValueType[] value) {
        if (Objects.requireNonNull(value, "value").length == 1) {
            return value[0].name();
        }
        AppendableCharSequence seq = new AppendableCharSequence(30);
        for (int i = 0; i < value.length; i++) {
            seq.append(value[i].name());
            if (i != value.length - 1) {
                seq.append(", ");
            }
        }
        return seq;
    }

    @Override
    public HeaderValueType[] toValue(CharSequence value) {
        CharSequence[] s = StrUtil.splitToArray(Objects.requireNonNull(value, "value"), ',');
        HeaderValueType[] result = new HeaderValueType[s.length];
        for (int i = 0; i < s.length; i++) {
            result[i] = new CharSequenceHeader(StrUtil.trim(s[i]));
        }
        return result;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy