com.yahoo.application.container.handler.Headers Maven / Gradle / Ivy
Show all versions of application Show documentation
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.application.container.handler;
import com.yahoo.api.annotations.Beta;
import com.yahoo.jdisc.HeaderFields;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* A multi-map for Request and Response header fields.
*
* @see Request
* @see Response
* @author Einar M R Rosenvinge
* @author Simon Thoresen Hult
*/
@Beta
public class Headers implements Map> {
private final HeaderFields h = new HeaderFields();
@Override
public int size() {
return h.size();
}
@Override
public boolean isEmpty() {
return h.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return h.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return h.containsValue(value);
}
@Override
public List get(Object key) {
return h.get(key);
}
@Override
public List put(String key, List value) {
return h.put(key, value);
}
@Override
public List remove(Object key) {
return h.remove(key);
}
@Override
public void putAll(Map extends String, ? extends List> m) {
h.putAll(m);
}
@Override
public void clear() {
h.clear();
}
@Override
public Set keySet() {
return h.keySet();
}
@Override
public Collection> values() {
return h.values();
}
@Override
public Set>> entrySet() {
return h.entrySet();
}
@Override
public String toString() {
return h.toString();
}
@Override
public boolean equals(Object obj) {
return obj instanceof Headers && h.equals(((Headers)obj).h);
}
@Override
public int hashCode() {
return h.hashCode();
}
/**
* Convenience method for checking whether or not a named header contains a specific value. If the named header
* is not set, or if the given value is not contained within that header's value list, this method returns
* false.
*
* NOTE: This method is case-SENSITIVE.
*
* @param key The key whose values to search in.
* @param value The values to search for.
* @return True if the given value was found in the named header.
* @see #containsIgnoreCase
*/
public boolean contains(String key, String value) {
return h.contains(key, value);
}
/**
* Convenience method for checking whether or not a named header contains a specific value, regardless of case.
* If the named header is not set, or if the given value is not contained within that header's value list, this
* method returns false.
*
* NOTE: This method is case-INSENSITIVE.
*
* @param key The key whose values to search in.
* @param value The values to search for, ignoring case.
* @return True if the given value was found in the named header.
* @see #contains
*/
public boolean containsIgnoreCase(String key, String value) {
return h.containsIgnoreCase(key, value);
}
/**
* Adds the given value to the entry of the specified key. If no entry exists for the given key, a new one is
* created containing only the given value.
*
* @param key The key with which the specified value is to be associated.
* @param value The value to be added to the list associated with the specified key.
*/
public void add(String key, String value) {
h.add(key, value);
}
/**
* Adds the given values to the entry of the specified key. If no entry exists for the given key, a new one is
* created containing only the given values.
*
* @param key The key with which the specified value is to be associated.
* @param values The values to be added to the list associated with the specified key.
*/
public void add(String key, List values) {
h.add(key, values);
}
/**
* Adds all the entries of the given map to this. This is the same as calling {@link #add(String, List)} for each
* entry in values
.
*
* @param values The values to be added to this.
*/
public void addAll(Map extends String, ? extends List> values) {
h.addAll(values);
}
/**
* Convenience method to call {@link #put(String, List)} with a singleton list that contains the specified
* value.
*
* @param key The key of the entry to put.
* @param value The value to put.
* @return The previous value associated with key
, or null
if there was no mapping for
* key
.
*/
public List put(String key, String value) {
return h.put(key, value);
}
/**
* Removes the given value from the entry of the specified key.
*
* @param key the key of the entry to remove from
* @param value the value to remove from the entry
* @return true if the value was removed
*/
public boolean remove(String key, String value) {
return h.remove(key, value);
}
/**
* Convenience method for retrieving the first value of a named header field. If the header is not set, or if the
* value list is empty, this method returns null.
*
* @param key the key whose first value to return.
* @return the first value of the named header, or null.
*/
public String getFirst(String key) {
return h.getFirst(key);
}
/**
* Convenience method for checking whether a named header field is true. To satisfy this, the
* header field needs to have at least 1 entry, and Boolean.valueOf() of all its values must parse as
* true.
*
* @param key the key whose values to parse as a boolean
* @return the boolean value of the named header
*/
public boolean isTrue(String key) {
return h.isTrue(key);
}
/**
* Returns an unmodifiable list of all key-value pairs of this. This provides a flattened view on the content of
* this map.
*
* @return the collection of entries
*/
public List> entries() {
return h.entries();
}
}