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

ru.tinkoff.kora.http.client.ok.OkHttpHeaders Maven / Gradle / Ivy

package ru.tinkoff.kora.http.client.ok;

import jakarta.annotation.Nullable;
import okhttp3.Headers;
import org.jetbrains.annotations.NotNull;
import ru.tinkoff.kora.http.common.header.HttpHeaders;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public final class OkHttpHeaders implements HttpHeaders {
    private final Headers headers;

    public OkHttpHeaders(Headers headers) {
        this.headers = headers;
    }

    @Nullable
    @Override
    public String getFirst(String name) {
        return this.headers.get(name);
    }

    @Override
    public List getAll(String name) {
        return this.headers.values(name);
    }

    @Override
    public boolean has(String key) {
        return this.headers.get(key) != null;
    }

    @Override
    public int size() {
        return this.headers.size();
    }

    @Override
    public Set names() {
        return this.headers.names();
    }

    @NotNull
    @Override
    public Iterator>> iterator() {
        var i = this.headers.names().iterator();
        return new Iterator<>() {
            @Override
            public boolean hasNext() {
                return i.hasNext();
            }

            @Override
            public Map.Entry> next() {
                var header = i.next();
                return Map.entry(header, headers.values(header));
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy