Reputation: 23
I'm using Jetty 9.4 HttpClient to try and restart a large file download. I'm using Jetty 9.4 server.
final InputStreamResponseListener listener = new
InputStreamResponseListener();
final Request request = httpClient.newRequest(urlString); request.scheme(getUriScheme(urlString)).method(HttpMethod.GET).version(HttpVersion.HTTP_1_1).send(listener);
if (range > 0){
request.header("Range", "bytes=" + file.length() + "-")
}
final Response response = listener.get(getHttpConnTimeout(), TimeUnit.SECONDS);
// Get content length from response header
contentLength = response.getHeaders().getField(HttpHeader.CONTENT_LENGTH).getLongValue();
if (response.getStatus() == HttpStatus.PARTIAL_CONTENT_206) {
return listener.getInputStream();
}
if (response.getStatus() == HttpStatus.OK_200) {
return listener.getInputStream();
}
However, when I use Java's implementation everything works fine (meaning not using Jetty 9 HttpClient)
if (httpURLConnection != null) {
// This works
httpURLConnection.setRequestProperty("Range", "bytes=" + file.length() + "-");
}
if (httpsURLConnection != null) {
// This works
httpsURLConnection.setRequestProperty("Range", "bytes=" + file.length() + "-");
}
What am I doing wrong? Anyone have a working example?
Upvotes: 1
Views: 353
Reputation: 73
By default Microsoft IIS accepts range in http request but it is not true for Jetty.
Actually the server admin should configure the jetty as described in this link:
Upvotes: 0
Reputation: 23
Julian is correct. It helped me eliminate the Jetty client as the code issue. It turned out that Jetty server required "partial" (aka accept ranges) downloads to do the following (and Jetty HttpClient will not work with partials otherwise.):
ResourceHandler rh = new ResourceHandler();
rh.setAcceptRanges(true);
It's working nicely now. My code snippet has been modified in hopes of helping someone else in the future.
Upvotes: 1
Reputation: 42075
It's (AFAIU) "header()", not "param()".
Also, "Content-Range" does not belong into the request.
Upvotes: 0