}
// If an entity was set during the call, copy it to the output
// stream;
if (response.getEntity() != null) {
Representation entity = response.getEntity();
if (entity.getExpirationDate() != null) {
responseHeaders.add(HttpConstants.HEADER_EXPIRES, response
.getHttpCall().formatDate(
entity.getExpirationDate(), false));
}
if (!entity.getEncodings().isEmpty()) {
StringBuilder value = new StringBuilder();
for (Encoding encoding : entity.getEncodings()) {
if (!encoding.equals(Encoding.IDENTITY)) {
if (value.length() > 0)
value.append(", ");
value.append(encoding.getName());
}
responseHeaders.add(
HttpConstants.HEADER_CONTENT_ENCODING, value
.toString());
}
}
if (!entity.getLanguages().isEmpty()) {
StringBuilder value = new StringBuilder();
for (int i = 0; i < entity.getLanguages().size(); i++) {
if (i > 0)
value.append(", ");
value.append(entity.getLanguages().get(i).getName());
}
responseHeaders.add(HttpConstants.HEADER_CONTENT_LANGUAGE,
value.toString());
}
if (entity.getMediaType() != null) {
StringBuilder contentType = new StringBuilder(entity
.getMediaType().getName());
if (entity.getCharacterSet() != null) {
// Specify the character set parameter
contentType.append("; charset=").append(
entity.getCharacterSet().getName());
}
responseHeaders.add(HttpConstants.HEADER_CONTENT_TYPE,
contentType.toString());
}
if (entity.getModificationDate() != null) {
responseHeaders.add(HttpConstants.HEADER_LAST_MODIFIED,
response.getHttpCall().formatDate(
entity.getModificationDate(), false));
}
if (entity.getTag() != null) {
responseHeaders.add(HttpConstants.HEADER_ETAG, entity
.getTag().format());
}
if (response.getEntity().getSize() != Representation.UNKNOWN_SIZE) {
responseHeaders.add(HttpConstants.HEADER_CONTENT_LENGTH,