Search in sources :

Example 1 with HeaderIterator

use of org.openecard.apache.http.HeaderIterator in project open-ecard by ecsec.

the class HttpAppPluginActionHandler method readReqHeaders.

private Headers readReqHeaders(HttpRequest httpRequest) {
    Headers headers = new Headers();
    // loop over all headers in the request
    HeaderIterator it = httpRequest.headerIterator();
    while (it.hasNext()) {
        Header next = it.nextHeader();
        String name = next.getName();
        String value = next.getValue();
        if (isMultiValueHeaderType(name)) {
            for (String part : value.split(",")) {
                headers.addHeader(name, part.trim());
            }
        } else {
            headers.addHeader(name, value);
        }
    }
    return headers;
}
Also used : Header(org.openecard.apache.http.Header) Headers(org.openecard.addon.bind.Headers) HeaderIterator(org.openecard.apache.http.HeaderIterator)

Example 2 with HeaderIterator

use of org.openecard.apache.http.HeaderIterator in project open-ecard by ecsec.

the class Http11Response method copyHttpResponse.

/**
 * Copy the content of a HttpResponse to another instance.
 *
 * @param in HttpResponse
 * @param out HttpResponse
 */
public static void copyHttpResponse(HttpResponse in, HttpResponse out) {
    // remove and copy headers
    HeaderIterator headIt = out.headerIterator();
    while (headIt.hasNext()) {
        headIt.nextHeader();
        headIt.remove();
    }
    headIt = in.headerIterator();
    while (headIt.hasNext()) {
        Header next = headIt.nextHeader();
        out.addHeader(next);
    }
    // set entity stuff
    if (in.getEntity() != null) {
        HttpEntity entity = in.getEntity();
        out.setEntity(entity);
        if (entity.getContentType() != null) {
            out.setHeader(entity.getContentType());
        }
        if (entity.getContentEncoding() != null) {
            out.setHeader(entity.getContentEncoding());
        }
        if (entity.getContentLength() > 0) {
            out.setHeader(HeaderTypes.CONTENT_LENGTH.fieldName(), Long.toString(entity.getContentLength()));
        }
    // TODO: use chunked, repeatable and streaming attribute from entity
    }
    // copy rest
    Locale l = in.getLocale();
    if (l != null) {
        out.setLocale(l);
    }
    out.setStatusLine(in.getStatusLine());
}
Also used : Locale(java.util.Locale) Header(org.openecard.apache.http.Header) HttpEntity(org.openecard.apache.http.HttpEntity) HeaderIterator(org.openecard.apache.http.HeaderIterator)

Aggregations

Header (org.openecard.apache.http.Header)2 HeaderIterator (org.openecard.apache.http.HeaderIterator)2 Locale (java.util.Locale)1 Headers (org.openecard.addon.bind.Headers)1 HttpEntity (org.openecard.apache.http.HttpEntity)1