mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
b513a48418
Range headers should not be sent when requesting the entire resource. This fixes compatibility with Microsoft IIS web server. Introduced in work on issue #1788 Change-Id: I151a2f15d4f5e95531e16d5372ee9a051135f12f
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
goog.provide('shaka.util.Networking');
|
|
|
|
|
|
/**
|
|
* A collection of shared utilities that bridge the gap between our networking
|
|
* code and the other parts of our code base. This is to allow
|
|
* |shaka.net.NetworkingEngine| to remain general.
|
|
*
|
|
* @final
|
|
*/
|
|
shaka.util.Networking = class {
|
|
/**
|
|
* Create a request message for a segment. Providing |start| and |end|
|
|
* will set the byte range. A non-zero start must be provided for |end| to
|
|
* be used.
|
|
*
|
|
* @param {!Array.<string>} uris
|
|
* @param {?number} start
|
|
* @param {?number} end
|
|
* @param {shaka.extern.RetryParameters} retryParameters
|
|
* @return {shaka.extern.Request}
|
|
*/
|
|
static createSegmentRequest(uris, start, end, retryParameters) {
|
|
const request = shaka.net.NetworkingEngine.makeRequest(
|
|
uris, retryParameters);
|
|
|
|
if (start == 0 && end == null) {
|
|
// This is a request for the entire segment. The Range header is not
|
|
// required. Note that some web servers don't accept Range headers, so
|
|
// don't set one if it's not strictly required.
|
|
} else {
|
|
if (end) {
|
|
request.headers['Range'] = 'bytes=' + start + '-' + end;
|
|
} else {
|
|
request.headers['Range'] = 'bytes=' + start + '-';
|
|
}
|
|
}
|
|
|
|
return request;
|
|
}
|
|
};
|