mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
64896d70b0
This reflects changes in Google's policy on JavaScript license headers, which should be smaller to avoid increasing the size of the binary unnecessarily. This also updates the company name from "Google, Inc" to "Google LLC". Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
/** @license
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.net.HttpPluginUtils');
|
|
|
|
goog.require('shaka.log');
|
|
goog.require('shaka.util.Error');
|
|
goog.require('shaka.util.StringUtils');
|
|
|
|
|
|
/**
|
|
* @summary A set of http networking utility functions.
|
|
* @exportDoc
|
|
*/
|
|
shaka.net.HttpPluginUtils = class {
|
|
/**
|
|
* @param {!Object.<string,string>} headers
|
|
* @param {BufferSource} data
|
|
* @param {number} status
|
|
* @param {string} uri
|
|
* @param {string} responseURL
|
|
* @param {shaka.net.NetworkingEngine.RequestType} requestType
|
|
* @return {!shaka.extern.Response}
|
|
*/
|
|
static makeResponse(headers, data, status, uri, responseURL, requestType) {
|
|
if (status >= 200 && status <= 299 && status != 202) {
|
|
// Most 2xx HTTP codes are success cases.
|
|
/** @type {shaka.extern.Response} */
|
|
const response = {
|
|
uri: responseURL || uri,
|
|
originalUri: uri,
|
|
data: data,
|
|
headers: headers,
|
|
fromCache: !!headers['x-shaka-from-cache'],
|
|
};
|
|
return response;
|
|
} else {
|
|
let responseText = null;
|
|
try {
|
|
responseText = shaka.util.StringUtils.fromBytesAutoDetect(data);
|
|
} catch (exception) {}
|
|
shaka.log.debug('HTTP error text:', responseText);
|
|
|
|
const severity = status == 401 || status == 403 ?
|
|
shaka.util.Error.Severity.CRITICAL :
|
|
shaka.util.Error.Severity.RECOVERABLE;
|
|
throw new shaka.util.Error(
|
|
severity,
|
|
shaka.util.Error.Category.NETWORK,
|
|
shaka.util.Error.Code.BAD_HTTP_STATUS,
|
|
uri,
|
|
status,
|
|
responseText,
|
|
headers,
|
|
requestType);
|
|
}
|
|
}
|
|
};
|