ArtifactControllerHelper { public static void provideArtifactHeaders(HttpServletResponse response, RepositoryPath path) throws IOException { if (path == null || Files.notExists(path) || Files.isDirectory(path)) { response.setStatus(HttpStatus.NOT_FOUND.value()); return; } RepositoryFileAttributes fileAttributes = Files.readAttributes(path, RepositoryFileAttributes.class); response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(fileAttributes.size())); response.setHeader(HttpHeaders.LAST_MODIFIED, DateTimeFormatter.RFC_1123_DATE_TIME.format( ZonedDateTime.ofInstant(fileAttributes.lastModifiedTime().toInstant(), ZoneId.systemDefault()))); String contentType = getContentType(path); response.setContentType(contentType); response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes"); path.getFileSystem().provider().resolveChecksumPathMap(path).forEach((key, value) -> { String checksumValue; try { checksumValue = new String(Files.readAllBytes(value), StandardCharsets.UTF_8).trim(); } catch (IOException ioe) { return; } String checksumName = String.format("Checksum-%s", key.toUpperCase().replace("-", "")); response.setHeader(checksumName, checksumValue); }); } private  ArtifactControllerHelper(); static void handlePartialDownload(InputStream is,
                                             HttpHeaders headers,
                                             HttpServletResponse response); static boolean isRangedRequest(HttpHeaders headers); static void provideArtifactHeaders(HttpServletResponse response,
                                              RepositoryPath path); static final String MULTIPART_BOUNDARY; }
@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test void provideArtifactHeaders(@MavenRepository(repositoryId = REPOSITORY_RELEASES_8) Repository repository, @MavenTestArtifact(repositoryId = REPOSITORY_RELEASES_8, id = "org.carlspring.strongbox:provide-artifact-headers", versions = "1.0") Path artifactPath) throws IOException { HttpServletResponse response = new MockHttpServletResponse(); RepositoryPath artifactRepositoryPath = (RepositoryPath) artifactPath.normalize(); ArtifactControllerHelper.provideArtifactHeaders(response, artifactRepositoryPath); assertThat(response.getHeader(HttpHeaders.CONTENT_LENGTH)).isNotEmpty(); assertThat(response.getHeader(HttpHeaders.LAST_MODIFIED)).isNotEmpty(); assertThat(response.getContentType()).isEqualTo(MediaType.APPLICATION_OCTET_STREAM_VALUE); assertThat(response.getHeader(HttpHeaders.ACCEPT_RANGES)).isEqualTo("bytes"); }