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

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

The newest version!
package org.zodiac.netty.http.headers;

import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.cookie.ClientCookieEncoder;
import io.netty.handler.codec.http.cookie.Cookie;
import io.netty.handler.codec.http.cookie.ServerCookieDecoder;

import java.util.Objects;
import java.util.Set;

final class CookieHeaderNetty428 extends AbstractHeader {

    private static final Cookie[] EMPTY = new Cookie[0];
    private final boolean strict;

    CookieHeaderNetty428(boolean strict) {
        super(Cookie[].class, HttpHeaderNames.COOKIE);
        this.strict = strict;
    }

    @Override
    public CharSequence toCharSequence(Cookie[] value) {
        Objects.requireNonNull(value, "value");
        return strict ? ClientCookieEncoder.STRICT.encode(value) : ClientCookieEncoder.LAX.encode(value);
    }

    @Override
    public Cookie[] toValue(CharSequence value) {
        ServerCookieDecoder decoder = strict ? ServerCookieDecoder.STRICT : ServerCookieDecoder.LAX;
        Set result = decoder.decode(Objects.requireNonNull(value, "value").toString());
        return result == null ? EMPTY : result.toArray(new Cookie[result.size()]);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy