Class: shaka.net.HttpFetchPlugin

A networking plugin to handle http and https URIs via the Fetch API.

Constructor

new HttpFetchPlugin()

A networking plugin to handle http and https URIs via the Fetch API.

Source:

Classes

BodyBuffer_

Members

AbortController_ :function(new:AbortController)

Overridden in unit tests, but compiled out in production.
Type:
  • function(new:AbortController)
Source:

BYOB_CHUNK_SIZE_ :number

The size of the reusable BYOB buffer for reads after the first.
Type:
  • number
Source:

fetch_ :function(string, !RequestInit)

Overridden in unit tests, but compiled out in production.
Type:
  • function(string, !RequestInit)
Source:

Headers_ :function(new:Headers)

Overridden in unit tests, but compiled out in production.
Type:
  • function(new:Headers)
Source:

ReadableStreamBYOBReader_ :function|undefined

Overridden in unit tests, but compiled out in production. It is an interface in the externs, so it can't be typed as a constructor.
Type:
  • function | undefined
Source:

Methods

getReader_(bodynon-null, contentLength, headersnon-null) → {{reader: (!ReadableStreamDefaultReader|!ReadableStreamBYOBReader), byob: boolean}}

Gets a reader of the body. A BYOB ("bring your own buffer") reader is used when the browser supports it for fetch bodies and the size of the body is known, so that reads can reuse backing memory. Otherwise, a default reader is used.
Parameters:
Name Type Description
body ReadableStream
contentLength number
headers Headers
Source:
Returns:
Type
{reader: (!ReadableStreamDefaultReader|!ReadableStreamBYOBReader), byob: boolean}

headersToGenericObject_(headersnon-null) → {Object<string, string>}

Parameters:
Name Type Description
headers Headers
Source:
Returns:
Type
Object<string, string>

isSupported() → {boolean}

Determine if the Fetch API is supported in the browser. Note: this is deliberately exposed as a method to allow the client app to use the same logic as Shaka when determining support.
Source:
Returns:
Type
boolean

parse(uri, request, requestType, progressUpdated, headersReceived, config) → {shaka.extern.IAbortableOperation<shaka.extern.Response>}

Parameters:
Name Type Description
uri string
request shaka.extern.Request
requestType shaka.net.NetworkingEngine.RequestType
progressUpdated shaka.extern.ProgressUpdated Called when a progress event happened.
headersReceived shaka.extern.HeadersReceived Called when the headers for the download are received, but before the body is.
config shaka.extern.SchemePluginConfig
Source:
Returns:
Type
shaka.extern.IAbortableOperation<shaka.extern.Response>

readWithByob_(readernon-null, contentLength, onRead, copyChunks) → {Promise<!ArrayBuffer>}

Reads the first chunk directly into the response buffer and reads later chunks into a reusable buffer. Every read transfers the supplied buffer: the view is detached, and the memory comes back in the result.
Parameters:
Name Type Description
reader ReadableStreamBYOBReader
contentLength number
onRead function(?Uint8Array): !Promise
copyChunks boolean Whether onRead gets copies of the data. The first chunk shares the response buffer, and later chunks are detached by the next read, so a stream data callback gets separate copies.
Source:
Returns:
Type
Promise<!ArrayBuffer>

readWithDefault_(readernon-null, contentLength, onRead) → {Promise<!ArrayBuffer>}

Reads a body with a default reader.
Parameters:
Name Type Description
reader ReadableStreamDefaultReader
contentLength number
onRead function(?Uint8Array): !Promise
Source:
Returns:
Type
Promise<!ArrayBuffer>

request_(uri, request, requestType, initnon-null, abortStatus, progressUpdated, headersReceived, streamDataCallbacknullable, minBytes) → {Promise<!shaka.extern.Response>}

Parameters:
Name Type Attributes Description
uri string
request shaka.extern.Request
requestType shaka.net.NetworkingEngine.RequestType
init RequestInit
abortStatus shaka.net.HttpFetchPlugin.AbortStatus_
progressUpdated shaka.extern.ProgressUpdated
headersReceived shaka.extern.HeadersReceived
streamDataCallback ?function(BufferSource): !Promise <nullable>
minBytes number
Source:
Returns:
Type
Promise<!shaka.extern.Response>

Type Definitions

AbortStatus_

Type:
  • {canceled: boolean, timedOut: boolean}
Properties:
Name Type Description
canceled boolean Indicates if the request was canceled.
timedOut boolean Indicates if the request timed out.
Source: