-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(net): Add shaka.net.NetworkingUtils (#5756)
- Loading branch information
Showing
5 changed files
with
43 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*! @license | ||
* Shaka Player | ||
* Copyright 2016 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
goog.provide('shaka.net.NetworkingUtils'); | ||
|
||
goog.require('shaka.net.NetworkingEngine'); | ||
|
||
|
||
/** | ||
* @summary Networking utility functions. | ||
*/ | ||
shaka.net.NetworkingUtils = class { | ||
/** | ||
* @param {string} uri | ||
* @param {!shaka.net.NetworkingEngine} netEngine | ||
* @param {shaka.extern.RetryParameters} retryParams | ||
* @return {!Promise.<string>} | ||
*/ | ||
static async getMimeType(uri, netEngine, retryParams) { | ||
const type = shaka.net.NetworkingEngine.RequestType.MANIFEST; | ||
|
||
const request = shaka.net.NetworkingEngine.makeRequest([uri], retryParams); | ||
request.method = 'HEAD'; | ||
|
||
const response = await netEngine.request(type, request).promise; | ||
|
||
// https://bit.ly/2K9s9kf says this header should always be available, | ||
// but just to be safe: | ||
const mimeType = response.headers['content-type']; | ||
return mimeType ? mimeType.toLowerCase().split(';').shift() : ''; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters