mirror of
https://github.com/samsonjs/media.git
synced 2026-04-01 10:35:48 +00:00
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:
parent
1613c9c7a8
commit
224fc2eef8
1 changed files with 7 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue