Skip to content

Commit 8db98ba

Browse files
npoltorapavloMichael Fiess
authored and
Michael Fiess
committed
expose Agent in http_wrap (pxscene#1678)
* expose Agent in http_wrap * update CI tests to newer version * add capabilities.network.http2
1 parent 1506496 commit 8db98ba

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

examples/pxScene2d/src/pxScene2d.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,7 @@ pxScene2d::pxScene2d(bool top, pxScriptView* scriptView)
19821982
//
19831983
// capabilities.network.cors = 1
19841984
// capabilities.network.corsResources = 1
1985+
// capabilities.network.http2 = 2
19851986
//
19861987
// capabilities.metrics.textureMemory = 1
19871988

@@ -2017,6 +2018,8 @@ pxScene2d::pxScene2d(bool top, pxScriptView* scriptView)
20172018

20182019
#endif // ENABLE_ACCESS_CONTROL_CHECK
20192020

2021+
networkCapabilities.set("http2", 2);
2022+
20202023
mCapabilityVersions.set("network", networkCapabilities);
20212024

20222025
rtObjectRef metricsCapabilities = new rtMapObject;

examples/pxScene2d/src/rcvrcore/http_wrap.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function Module(moduleName, appSceneContext) {
3636
this.get = function (options, callback) {
3737
return new Request(moduleName, appSceneContext, options, callback).end();
3838
};
39+
this.Agent = Agent;
3940
}
4041

4142
module.exports = Module;
@@ -100,10 +101,25 @@ function Request(moduleName, appSceneContext, options, callback) {
100101
}
101102

102103
if (!isBlocked) {
104+
var module = moduleName === 'http' ? http : (moduleName === 'https' ? https : (isV8 ? https : http2));
105+
106+
// for v8 http/https/http2 are the same, set protocol explicitly
103107
if (isV8 && !options.protocol) {
104108
options.protocol = defaultProtocol;
105109
}
106-
var module = moduleName === 'http' ? http : (moduleName === 'https' ? https : (isV8 ? https : http2));
110+
111+
// convert a dummy Agent into a real one
112+
if (options.agent instanceof Agent) {
113+
var agentObj = options.agent;
114+
var newAgent = isV8 ? null : new module.Agent(agentObj.options);
115+
options.agent = newAgent;
116+
agentObj.once('destroy', function () {
117+
if (newAgent) {
118+
newAgent.destroy.apply(newAgent, arguments);
119+
}
120+
});
121+
}
122+
107123
httpRequest = module.request.call(null, options);
108124

109125
httpRequest.once('response', function (httpResponse) {
@@ -286,6 +302,22 @@ Response.prototype = Object.create(EventEmitter.prototype);
286302
Response.prototype.constructor = Response;
287303
Response.prototype.blocked = false;
288304

305+
function Agent(options) {
306+
EventEmitter.call(this);
307+
308+
log.message(4, "creating a new agent");
309+
this.options = options;
310+
311+
var self = this;
312+
this.destroy = function () {
313+
log.message(4, "emit agent 'destroy'");
314+
self.emit('destroy');
315+
};
316+
}
317+
318+
Agent.prototype = Object.create(EventEmitter.prototype);
319+
Agent.prototype.constructor = Agent;
320+
289321
function Utils() {
290322
}
291323

tests/pxScene2d/testRunner/tests.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
{"url":"../tests/test_pxImage9.js", "title":"test_pxImage9","useBaseURI":"true"},
2626
{"url":"../tests/test_textureMemoryUsage.js", "title":"test_textureMemoryUsage.js","useBaseURI":"true"},
2727
{"url":"../tests/test_moveForwardBackward.js", "title":"test_moveForwardBackward","useBaseURI":"true"},
28-
{"url":"../tests/test_imports_v3.js", "title":"test_imports","useBaseURI":"true"},
28+
{"url":"../tests/test_imports_v4.js", "title":"test_imports","useBaseURI":"true"},
2929
{"url":"../tests/test_permissions_v5.js", "title":"test_permissions","useBaseURI":"true"},
30-
{"url":"../tests/test_permissions_http2_v5.js", "title":"test_permissions_http2","useBaseURI":"true"},
31-
{"url":"../tests/test_cors_v5.js", "title":"test_cors","useBaseURI":"true"},
30+
{"url":"../tests/test_permissions_http2_v6.js", "title":"test_permissions_http2","useBaseURI":"true"},
31+
{"url":"../tests/test_cors_v6.js", "title":"test_cors","useBaseURI":"true"},
32+
{"url":"../tests/test_cors_http2_v6.js", "title":"test_cors_http2","useBaseURI":"true"},
3233
{"url":"../tests/test_textFontRejection.js", "title":"test_textFontRejection","useBaseURI":"true"},
3334
{"url":"../tests/test_onBlur_loseFocusChain.js","title":"test_onBlur_loseFocusChain", "useBaseURI":"true"},
3435
{"url":"../tests/test_promiseRejectionAnimation.js", "title":"test_promiseRejectionAnimation","useBaseURI":"true"},

0 commit comments

Comments
 (0)