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

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

Introduction

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

Prototype

public Header[] getAllHeaders() 

Source Link

Usage

From source file:org.trancecode.xproc.step.RequestParser.java

private HttpRequestBase constructMethod(final String method, final URI hrefUri) {
    final HttpEntity httpEntity = request.getEntity();
    final HeaderGroup headers = request.getHeaders();
    if (StringUtils.equalsIgnoreCase(HttpPost.METHOD_NAME, method)) {
        final HttpPost httpPost = new HttpPost(hrefUri);
        for (final Header h : headers.getAllHeaders()) {
            if (!StringUtils.equalsIgnoreCase("Content-Type", h.getName())) {
                httpPost.addHeader(h);//from   w  w w .ja va2 s . co m
            }
        }
        httpPost.setEntity(httpEntity);
        return httpPost;
    } else if (StringUtils.equalsIgnoreCase(HttpPut.METHOD_NAME, method)) {
        final HttpPut httpPut = new HttpPut(hrefUri);
        httpPut.setEntity(httpEntity);
        return httpPut;
    } else if (StringUtils.equalsIgnoreCase(HttpDelete.METHOD_NAME, method)) {
        final HttpDelete httpDelete = new HttpDelete(hrefUri);
        httpDelete.setHeaders(headers.getAllHeaders());
        return httpDelete;
    } else if (StringUtils.equalsIgnoreCase(HttpGet.METHOD_NAME, method)) {
        final HttpGet httpGet = new HttpGet(hrefUri);
        httpGet.setHeaders(headers.getAllHeaders());
        return httpGet;

    } else if (StringUtils.equalsIgnoreCase(HttpHead.METHOD_NAME, method)) {
        final HttpHead httpHead = new HttpHead(hrefUri);
        httpHead.setHeaders(headers.getAllHeaders());
        return httpHead;
    }
    return null;
}

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

/**
 * Returns a list of the header string values for the given header name.
 *
 * @param name header name (may be any case)
 * @return header string values or empty if not found
 *//*from   www .  j  a  va  2  s.co m*/
public List<String> getHeaderStringValues(final String name) {
    Object value = get(name);

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

    List<String> values = new ArrayList<>();
    HeaderGroup group = parseHeaderKeyValue(name, value);
    Header[] headers = group.getAllHeaders();

    for (Header header : headers) {
        String headerValue = header.getValue();

        if (headerValue != null) {
            values.add(headerValue);
        }
    }

    return values;
}