-
Notifications
You must be signed in to change notification settings - Fork 188
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
Prepare a StreamingOutput response when serving file downloads. #1829
Conversation
.get() | ||
.getResponseBodyAsStream(); | ||
PerRequestConfig unlimitedTimeout = new PerRequestConfig(); | ||
unlimitedTimeout.setRequestTimeoutInMs(-1); |
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.
The default 60 second timeout on our AsyncHttpClient is insufficient for large file downloads.
@@ -656,4 +668,56 @@ public Response downloadFileOverProxy( | |||
} | |||
|
|||
} | |||
|
|||
private static class NingOutputToJaxRsStreamingOutputWrapper implements AsyncHandler<Void>, StreamingOutput { |
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.
Fully open to suggestions on a better name for this, heh.
if (wrappedOutputStream == null) { | ||
wrappedOutputStream = output; | ||
try { | ||
requestBuilder.execute(this).get(); |
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.
We need to do it this way because the OutputStream
doesn't become available to us until Jersey actually calls write()
on this implementation. The alternative would be to begin the proxied request before waiting for Jersey, in which case we'd be back to buffering a potentially large response in memory.
The get()
here on the Future is also necessary because Jersey expects write()
to be a blocking call, and closes the provided OutputStream
after this method returns.
🚢 |
This prepares a 4k buffer and pipes the HTTP response InputStream to a jax-rs compatible StreamingOutput object.