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

ch.viascom.groundwork.foxhttp.header.FoxHttpHeader Maven / Gradle / Ivy

Go to download

The FoxHttp provides a fast and easy http client for java and android. It is part of the GroundWork Project by Viascom.

There is a newer version: 1.3.6
Show newest version
package ch.viascom.groundwork.foxhttp.header;

import ch.viascom.groundwork.foxhttp.type.HeaderTypes;
import lombok.Data;

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

/**
 * FoxHttpHeader stores headers
 *
 * @author [email protected]
 */
@Data
public class FoxHttpHeader implements Iterable {

    private List headerEntries = new ArrayList<>();

    @Override
    public Iterator iterator() {
        return headerEntries.iterator();
    }

    /**
     * Add a new header entry
     *
     * @param name  name of the header entry
     * @param value value of the header entry
     */
    public void addHeader(String name, String value) {
        if (value != null) {
            headerEntries.add(new HeaderEntry(name, value));
        }
    }

    /**
     * Add a new header entry
     *
     * @param name  name of the header entry
     * @param value value of the header entry
     */
    public void addHeader(HeaderTypes name, String value) {
        if (value != null) {
            headerEntries.add(new HeaderEntry(name.toString(), value));
        }
    }

    /**
     * Add a new map of header entries
     *
     * @param entries map of header entries
     */
    public void addHeader(Map entries) {
        for (Map.Entry entry : entries.entrySet()) {
            if (entry.getValue() != null) {
                headerEntries.add(new HeaderEntry(entry.getKey(), entry.getValue()));
            }
        }
    }

    /**
     * Add a new array of header entries
     *
     * @param entries array of header entries
     */
    public void addHeader(List entries) {
        headerEntries.addAll(entries);
    }

    /**
     * Get a specific header based on its name
     *
     * @param name name of the header
     * @return a specific header
     */
    public HeaderEntry getHeader(String name) {
        for (HeaderEntry headerField : getHeaderEntries()) {
            if (headerField.getName().equals(name)) {
                return headerField;
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy