Example usage for org.apache.http.message HeaderGroup getCondensedHeader

List of usage examples for org.apache.http.message HeaderGroup getCondensedHeader

Introduction

In this page you can find the example usage for org.apache.http.message HeaderGroup getCondensedHeader.

Prototype

public Header getCondensedHeader(String str) 

Source Link

Usage

From source file:com.joyent.manta.http.MantaHttpHeaders.java

/**
 * Returns the condensed value for an HTTP header that may contain multiple
 * elements.//w  w w  . ja  v  a  2 s  .  c  o  m
 *
 * @param name header name (may be any case)
 * @return Condensed HTTP header value as per RFC 2616
 */
private String getMultipleValuesAsString(final String name) {
    Object value = get(name);

    if (value == null) {
        return null;
    }

    if (value instanceof String) {
        return (String) value;
    }

    HeaderGroup group = parseHeaderKeyValue(name, value);
    Header condensed = group.getCondensedHeader(name);
    final String condensedValue;

    if (condensed != null) {
        condensedValue = condensed.getValue();
    } else {
        condensedValue = null;
    }

    return condensedValue;
}

From source file:com.joyent.manta.http.MantaHttpHeaders.java

/**
 * Returns the headers as an array of {@link org.apache.http.Header} instances.
 *
 * @return an array of {@link org.apache.http.Header} instances
 *//*w  w  w  .j a  v a2  s.  com*/
public Header[] asApacheHttpHeaders() {
    if (wrappedHeaders.isEmpty()) {
        return new Header[0];
    }

    final int length = wrappedHeaders.size();
    final Header[] headers = new Header[length];
    final MapIterator<String, Object> itr = wrappedHeaders.mapIterator();

    int i = 0;
    while (itr.hasNext()) {
        String key = itr.next();
        Object val = itr.getValue();

        final HeaderGroup extracted = parseHeaderKeyValue(key, val);
        headers[i++] = extracted.getCondensedHeader(key);
    }

    if (length == i) {
        return headers;
    }

    return Arrays.copyOfRange(headers, 0, i);
}