use of org.commonjava.indy.core.model.StoreHttpExchangeMetadata in project indy by Commonjava.
the class NPMContentAccessHandler method generateHttpMetadataHeaders.
private void generateHttpMetadataHeaders(final Transfer transfer, final List<Transfer> generated, final HttpServletRequest request, final Response response) {
if (transfer == null || !transfer.exists() || request == null || response == null) {
return;
}
Response customizedResponse = Response.fromResponse(response).header(ApplicationHeader.content_length.upperKey(), transfer.length()).header(ApplicationHeader.indy_origin.upperKey(), null).header(ApplicationHeader.transfer_encoding.upperKey(), null).lastModified(new Date(transfer.lastModified())).build();
Transfer metaTxfr = transfer.getSiblingMeta(HttpExchangeMetadata.FILE_EXTENSION);
if (metaTxfr == null) {
if (transfer.isDirectory()) {
metaTxfr = transfer.getChild(HttpExchangeMetadata.FILE_EXTENSION);
} else {
return;
}
}
final HttpExchangeMetadata metadata = new StoreHttpExchangeMetadata(request, customizedResponse);
try (OutputStream out = metaTxfr.openOutputStream(TransferOperation.GENERATE, false)) {
if (out != null) {
out.write(mapper.writeValueAsBytes(metadata));
}
} catch (final IOException e) {
logger.error("Failed to write metadata for HTTP exchange to: {}. Reason: {}", metaTxfr, e);
}
if (generated == null) {
return;
}
for (Transfer t : generated) {
generateHttpMetadataHeaders(t, request, response);
}
}
Aggregations