001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2010–2011 ApexIdentity Inc.
015 * Portions Copyright 2011-2015 ForgeRock AS.
016 */
017
018package org.forgerock.http.header;
019
020import static java.util.Collections.*;
021
022import java.util.List;
023
024import org.forgerock.http.protocol.Header;
025
026/**
027 * An undecoded HTTP message header. Values are always immutable.
028 */
029public class GenericHeader extends Header {
030    /** The header name. */
031    private String name;
032
033    /** The header values. */
034    private List<String> values;
035
036    /**
037     * Constructs a new header with the provided name and value.
038     *
039     * @param name
040     *            The header name.
041     * @param value
042     *            The header value.
043     */
044    public GenericHeader(String name, String value) {
045        this(name, singletonList(value));
046    }
047
048    /**
049     * Constructs a new header with the provided name and values.
050     *
051     * @param name
052     *            The header name.
053     * @param values
054     *            The header values.
055     */
056    public GenericHeader(String name, List<String> values) {
057        this.name = name;
058        this.values = unmodifiableList(values);
059    }
060
061    @Override
062    public String getName() {
063        return name;
064    }
065
066    /**
067     * {@inheritDoc}
068     * @return An immutable list of values for this header name.
069     */
070    @Override
071    public List<String> getValues() {
072        return values;
073    }
074}