Files
shaka-player/lib/util/networking.js
T
Joey Parrish b513a48418 Fix range header regression
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
2019-05-01 17:02:53 +00:00

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;
}
};