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;
}
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());
}
Aggregations