-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fix handling of artifact range requests #1445
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,13 @@ public interface DbArtifact { | |
* @return {@link InputStream} to read from artifact. | ||
*/ | ||
InputStream getFileInputStream(); | ||
|
||
/** | ||
* Creates an {@link InputStream} on a single range of this artifact. | ||
* The caller has to take care of closing the stream. | ||
* Repeatable calls open a new {@link InputStream}. | ||
* | ||
* @return {@link InputStream} to read from artifact. | ||
*/ | ||
InputStream getFileInputStream(long start, long end); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here an default implementation could be provided - one that skips the reading of input stream start. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,9 @@ public String getContentType() { | |
public InputStream getFileInputStream() { | ||
return decryptionFunction.apply(encryptedDbArtifact.getFileInputStream()); | ||
} | ||
|
||
@Override | ||
public InputStream getFileInputStream(long start, long end) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. start and end are pointers in the plain (decrypted input stream). |
||
return decryptionFunction.apply(encryptedDbArtifact.getFileInputStream(start, end)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,8 +285,8 @@ private static ResponseEntity<InputStream> handleMultipartRangeRequest(final DbA | |
final ServletOutputStream to = response.getOutputStream(); | ||
|
||
for (final ByteRange r : ranges) { | ||
try (final InputStream from = artifact.getFileInputStream()) { | ||
|
||
try (final InputStream from = artifact.getFileInputStream(r.getStart(), r.getEnd())) { | ||
// Add multipart boundary and header fields for every range. | ||
to.println(); | ||
to.println("--" + ByteRange.MULTIPART_BOUNDARY); | ||
|
@@ -316,7 +316,7 @@ private static ResponseEntity<InputStream> handleStandardRangeRequest(final DbAr | |
response.setContentLengthLong(r.getLength()); | ||
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); | ||
|
||
try (final InputStream from = artifact.getFileInputStream()) { | ||
try (final InputStream from = artifact.getFileInputStream(r.getStart(), r.getEnd())) { | ||
final ServletOutputStream to = response.getOutputStream(); | ||
copyStreams(from, to, progressListener, r.getStart(), r.getLength(), filename); | ||
} catch (final IOException e) { | ||
|
@@ -340,8 +340,6 @@ private static long copyStreams(final InputStream from, final OutputStream to, | |
long total = 0; | ||
int progressPercent = 1; | ||
|
||
ByteStreams.skipFully(from, start); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this method, now reads from 0 to length (exclusively) "final long start" is little bit misleading. |
||
|
||
long toRead = length; | ||
boolean toContinue = true; | ||
long shippedSinceLastEvent = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not add an additional dependency on com.google.common
wouldn't
do the same?