Skip to content

Commit

Permalink
Allowed network plugins to see the request type.
Browse files Browse the repository at this point in the history
Closes #602
Change-Id: Ib86389956c4908d94184abe8775d497b09a5f90e
  • Loading branch information
theodab committed Jan 6, 2017
1 parent 9153f68 commit 07ce752
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion externs/shaka/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ shakaExtern.Response;
/**
* Defines a plugin that handles a specific scheme.
*
* @typedef {!function(string, shakaExtern.Request):
* @typedef {!function(string,
* shakaExtern.Request,
* shaka.net.NetworkingEngine.RequestType):
* !Promise.<shakaExtern.Response>}
* @exportDoc
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/net/networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ shaka.net.NetworkingEngine.prototype.send_ = function(
}

var startTimeMs = Date.now();
return plugin(request.uris[index], request).then(function(response) {
return plugin(request.uris[index], request, type).then(function(response) {
if (response.timeMs === undefined)
response.timeMs = Date.now() - startTimeMs;

Expand Down
3 changes: 2 additions & 1 deletion test/net/networking_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ function() {
var request = createRequest('resolve://foo');
request.method = 'POST';

resolveScheme.and.callFake(function(uri, request) {
resolveScheme.and.callFake(function(uri, request, requestTypePassed) {
expect(uri).toBe(request.uris[0]);
expect(request).toEqual(request);

This comment has been minimized.

Copy link
@shaharmor

shaharmor May 3, 2017

This will always be true no?

This comment has been minimized.

Copy link
@joeyparrish

joeyparrish May 3, 2017

Member

Good catch. The mistake here is that we used the same variable name for the input ("var request") and the parameter passed to the callback. This would make sense if they had different names. We will fix it.

This comment has been minimized.

Copy link
@joeyparrish

joeyparrish May 3, 2017

Member

Note also the subtlety that "toEqual" and "toBe" are different in jasmine. The request object inside the callback should equal the request object from the caller, but will not necessarily be the same memory address.

This comment has been minimized.

Copy link
@joeyparrish

joeyparrish May 3, 2017

Member

Fixed in 22b736a. Thanks!

expect(requestTypePassed).toEqual(requestType);
return Promise.resolve({});
});
networkingEngine.request(requestType, request).catch(fail).then(done);
Expand Down

0 comments on commit 07ce752

Please sign in to comment.