Commit 224fc2ee by Oliver Woodman

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.
parent 1613c9c7
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment