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_OVERFLOW_CHUNK_SIZE_ :number

The size of the buffers read into with a BYOB reader once the body is larger than its Content-Length.
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: the data is then read straight into the buffer of the response, without allocating every chunk. Otherwise, a default reader.
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 a body with a BYOB reader, into a buffer of the expected length. Every read transfers that buffer: the view given to read() is detached, and the same memory comes back as the buffer of the result.
Parameters:
Name Type Description
reader ReadableStreamBYOBReader
contentLength number
onRead function(?Uint8Array): !Promise
copyChunks boolean Whether onRead gets copies of the data. The data read is a view of the buffer, which the next read detaches, so it must be copied if it is kept, as a stream data callback may do.
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: