Omit range header if the range is 0-.

Apparently some servers don't like it, and in general it's
unnecessary to set the header for this case.
This commit is contained in:
Oliver Woodman 2015-01-12 17:34:00 +00:00
parent 1613c9c7a8
commit 224fc2eef8

View file

@ -393,18 +393,22 @@ public class HttpDataSource implements DataSource {
connection.setRequestProperty(property.getKey(), property.getValue());
}
}
setRangeHeader(connection, dataSpec);
connection.setRequestProperty("User-Agent", userAgent);
connection.setRequestProperty("Range", buildRangeHeader(dataSpec));
connection.connect();
return connection;
}
private String buildRangeHeader(DataSpec dataSpec) {
private void setRangeHeader(HttpURLConnection connection, DataSpec dataSpec) {
if (dataSpec.position == 0 && dataSpec.length == C.LENGTH_UNBOUNDED) {
// Not required.
return;
}
String rangeRequest = "bytes=" + dataSpec.position + "-";
if (dataSpec.length != C.LENGTH_UNBOUNDED) {
rangeRequest += (dataSpec.position + dataSpec.length - 1);
}
return rangeRequest;
connection.setRequestProperty("Range", rangeRequest);
}
private long getContentLength(HttpURLConnection connection) {