Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hawkbit-ddi-resource: do not log range requests #1331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,38 +201,36 @@ public ResponseEntity<InputStream> downloadArtifact(@PathVariable("tenant") fina
if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
result = new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
} else {
final ActionStatus action = checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(),
final ActionStatus maybeAction = checkAndMaybeLogDownload(requestResponseContextHolder.getHttpServletRequest(),
target, module.getId());

final Long statusId = action.getId();

result = FileStreamingUtil.writeFileResponse(file, artifact.getFilename(), artifact.getCreatedAt(),
requestResponseContextHolder.getHttpServletResponse(),
requestResponseContextHolder.getHttpServletRequest(),
(length, shippedSinceLastEvent,
total) -> eventPublisher.publishEvent(new DownloadProgressEvent(
tenantAware.getCurrentTenant(), statusId, shippedSinceLastEvent,
serviceMatcher != null ? serviceMatcher.getBusId() : bus.getId())));

(length, shippedSinceLastEvent, total) -> {
if (maybeAction != null) {
eventPublisher.publishEvent(new DownloadProgressEvent(
tenantAware.getCurrentTenant(), maybeAction.getId(), shippedSinceLastEvent,
serviceMatcher != null ? serviceMatcher.getBusId() : bus.getId()));
}
});
}
}
return result;
}

private ActionStatus checkAndLogDownload(final HttpServletRequest request, final Target target, final Long module) {
private ActionStatus checkAndMaybeLogDownload(final HttpServletRequest request, final Target target, final Long module) {
final Action action = controllerManagement
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module)
.orElseThrow(() -> new SoftwareModuleNotAssignedToTargetException(module, target.getControllerId()));
final String range = request.getHeader("Range");

final String message;
// Logging range requests is pointless as there can be arbitrarily many of them.
final String range = request.getHeader("Range");
if (range != null) {
message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: "
+ request.getRequestURI();
} else {
message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI();
return null;
}

final String message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI();
return controllerManagement.addInformationalActionStatus(
entityFactory.actionStatus().create(action.getId()).status(Status.DOWNLOAD).message(message));
}
Expand Down Expand Up @@ -262,7 +260,7 @@ public ResponseEntity<Void> downloadArtifactMd5(@PathVariable("tenant") final St
final Artifact artifact = module.getArtifactByFilename(fileName)
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, fileName));

checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(), target, module.getId());
checkAndMaybeLogDownload(requestResponseContextHolder.getHttpServletRequest(), target, module.getId());

try {
FileStreamingUtil.writeMD5FileResponse(requestResponseContextHolder.getHttpServletResponse(),
Expand Down