ch.viascom.groundwork.foxhttp.header.FoxHttpHeader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of foxhttp Show documentation
Show all versions of foxhttp Show documentation
The FoxHttp provides a fast and easy http client for java and android. It is part of the GroundWork Project by Viascom.
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;
}
}