Skip to content

Commit 59c9989

Browse files
authored
feat(net): Add originalRequest to shaka.extern.Response (#7857)
1 parent 0a9aeb7 commit 59c9989

10 files changed

+37
-14
lines changed

externs/shaka/net.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ shaka.extern.Request;
130130
* status: (number|undefined),
131131
* headers: !Object.<string, string>,
132132
* timeMs: (number|undefined),
133-
* fromCache: (boolean|undefined)
133+
* fromCache: (boolean|undefined),
134+
* originalRequest: shaka.extern.Request
134135
* }}
135136
*
136137
* @description
@@ -158,6 +159,8 @@ shaka.extern.Request;
158159
* @property {(boolean|undefined)} fromCache
159160
* Optional. If true, this response was from a cache and should be ignored
160161
* for bandwidth estimation.
162+
* @property {shaka.extern.Request} originalRequest
163+
* The original request that gave rise to this response.
161164
*
162165
* @exportDoc
163166
*/

lib/net/data_uri_plugin.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ shaka.net.DataUriPlugin = class {
4141
headers: {
4242
'content-type': parsed.contentType,
4343
},
44+
originalRequest: request,
4445
};
4546

4647
return shaka.util.AbortableOperation.completed(response);

lib/net/http_fetch_plugin.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ shaka.net.HttpFetchPlugin = class {
6161
const minBytes = config.minBytesForProgressEvents || 0;
6262

6363
const pendingRequest = shaka.net.HttpFetchPlugin.request_(
64-
uri, requestType, init, abortStatus, progressUpdated, headersReceived,
65-
request.streamDataCallback, minBytes);
64+
uri, request, requestType, init, abortStatus, progressUpdated,
65+
headersReceived, request.streamDataCallback, minBytes);
6666

6767
/** @type {!shaka.util.AbortableOperation} */
6868
const op = new shaka.util.AbortableOperation(pendingRequest, () => {
@@ -94,6 +94,7 @@ shaka.net.HttpFetchPlugin = class {
9494

9595
/**
9696
* @param {string} uri
97+
* @param {shaka.extern.Request} request
9798
* @param {shaka.net.NetworkingEngine.RequestType} requestType
9899
* @param {!RequestInit} init
99100
* @param {shaka.net.HttpFetchPlugin.AbortStatus} abortStatus
@@ -104,8 +105,8 @@ shaka.net.HttpFetchPlugin = class {
104105
* @return {!Promise<!shaka.extern.Response>}
105106
* @private
106107
*/
107-
static async request_(uri, requestType, init, abortStatus, progressUpdated,
108-
headersReceived, streamDataCallback, minBytes) {
108+
static async request_(uri, request, requestType, init, abortStatus,
109+
progressUpdated, headersReceived, streamDataCallback, minBytes) {
109110
const fetch = shaka.net.HttpFetchPlugin.fetch_;
110111
const ReadableStream = shaka.net.HttpFetchPlugin.ReadableStream_;
111112
let response;
@@ -225,8 +226,8 @@ shaka.net.HttpFetchPlugin = class {
225226
const headers = shaka.net.HttpFetchPlugin.headersToGenericObject_(
226227
response.headers);
227228

228-
return shaka.net.HttpPluginUtils.makeResponse(
229-
headers, arrayBuffer, response.status, uri, response.url, requestType);
229+
return shaka.net.HttpPluginUtils.makeResponse(headers, arrayBuffer,
230+
response.status, uri, response.url, request, requestType);
230231
}
231232

232233
/**

lib/net/http_plugin_utils.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ shaka.net.HttpPluginUtils = class {
2424
* @param {number} status
2525
* @param {string} uri
2626
* @param {string} responseURL
27+
* @param {shaka.extern.Request} request
2728
* @param {shaka.net.NetworkingEngine.RequestType} requestType
2829
* @return {!shaka.extern.Response}
2930
*/
30-
static makeResponse(headers, data, status, uri, responseURL, requestType) {
31+
static makeResponse(headers, data, status, uri, responseURL, request,
32+
requestType) {
3133
goog.asserts.assert(data, 'Data should be non-null!');
3234

3335
if (status >= 200 && status <= 299 && status != 202) {
@@ -40,6 +42,7 @@ shaka.net.HttpPluginUtils = class {
4042
status: status,
4143
headers: headers,
4244
fromCache: !!headers['x-shaka-from-cache'],
45+
originalRequest: request,
4346
};
4447
return response;
4548
} else {

lib/net/http_xhr_plugin.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ shaka.net.HttpXHRPlugin = class {
7474
progressUpdated(currentTime - lastTime, event.loaded - lastLoaded,
7575
/* numBytesRemaining= */ 0);
7676
const response = shaka.net.HttpPluginUtils.makeResponse(headers,
77-
xhrResponse, xhr.status, uri, xhr.responseURL, requestType);
77+
xhrResponse, xhr.status, uri, xhr.responseURL, request,
78+
requestType);
7879
resolve(response);
7980
} catch (error) {
8081
goog.asserts.assert(error instanceof shaka.util.Error,

lib/offline/offline_scheme.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ shaka.offline.OfflineScheme = class {
3232
const offlineUri = shaka.offline.OfflineUri.parse(uri);
3333

3434
if (offlineUri && offlineUri.isManifest()) {
35-
return shaka.offline.OfflineScheme.getManifest_(uri);
35+
return shaka.offline.OfflineScheme.getManifest_(uri, request);
3636
}
3737

3838
if (offlineUri && offlineUri.isSegment()) {
3939
return shaka.offline.OfflineScheme.getSegment_(
40-
offlineUri.key(), offlineUri);
40+
offlineUri.key(), offlineUri, request);
4141
}
4242

4343
return shaka.util.AbortableOperation.failed(
@@ -50,16 +50,18 @@ shaka.offline.OfflineScheme = class {
5050

5151
/**
5252
* @param {string} uri
53+
* @param {shaka.extern.Request} request
5354
* @return {!shaka.extern.IAbortableOperation.<shaka.extern.Response>}
5455
* @private
5556
*/
56-
static getManifest_(uri) {
57+
static getManifest_(uri, request) {
5758
/** @type {shaka.extern.Response} */
5859
const response = {
5960
uri: uri,
6061
originalUri: uri,
6162
data: new ArrayBuffer(0),
6263
headers: {'content-type': 'application/x-offline-manifest'},
64+
originalRequest: request,
6365
};
6466

6567
return shaka.util.AbortableOperation.completed(response);
@@ -68,10 +70,11 @@ shaka.offline.OfflineScheme = class {
6870
/**
6971
* @param {number} id
7072
* @param {!shaka.offline.OfflineUri} uri
73+
* @param {shaka.extern.Request} request
7174
* @return {!shaka.extern.IAbortableOperation.<shaka.extern.Response>}
7275
* @private
7376
*/
74-
static getSegment_(id, uri) {
77+
static getSegment_(id, uri, request) {
7578
goog.asserts.assert(
7679
uri.isSegment(),
7780
'Only segment uri\'s should be given to getSegment');
@@ -90,6 +93,7 @@ shaka.offline.OfflineScheme = class {
9093
uri: uri,
9194
data: segment.data,
9295
headers: {},
96+
originalRequest: request,
9397
};
9498
})
9599
.finally(() => muxer.destroy());

test/media/streaming_engine_unit.js

+1
Original file line numberDiff line numberDiff line change
@@ -3461,6 +3461,7 @@ describe('StreamingEngine', () => {
34613461
originalUri: request.uris[0],
34623462
data: buffer,
34633463
headers: {},
3464+
originalRequest: request,
34643465
};
34653466
return shaka.util.AbortableOperation.completed(response);
34663467
});

test/net/networking_engine_unit.js

+1
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ () => {
12751275
originalUri: '',
12761276
data: new ArrayBuffer(5),
12771277
headers: {},
1278+
originalRequest: createRequest('fake'),
12781279
};
12791280
}
12801281
}); // describe('NetworkingEngine')

test/test/util/fake_networking_engine.js

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ shaka.test.FakeNetworkingEngine = class {
138138
originalUri: requestedUri,
139139
data: result,
140140
headers: headers,
141+
originalRequest: request,
141142
};
142143

143144
// Modify the response using the response filter, this allows the app

test/test/util/test_scheme.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ shaka.test.TestScheme = class {
8383
originalUri: uri,
8484
data: new ArrayBuffer(0),
8585
headers: {'content-type': 'application/x-test-manifest'},
86+
originalRequest: request,
8687
};
8788
return shaka.util.AbortableOperation.completed(response);
8889
}
@@ -127,7 +128,13 @@ shaka.test.TestScheme = class {
127128
}
128129

129130
/** @type {shaka.extern.Response} */
130-
const ret = {uri: uri, originalUri: uri, data: responseData, headers: {}};
131+
const ret = {
132+
uri: uri,
133+
originalUri: uri,
134+
data: responseData,
135+
headers: {},
136+
originalRequest: request,
137+
};
131138
return shaka.util.AbortableOperation.completed(ret);
132139
}
133140

0 commit comments

Comments
 (0)