feat(base-driver): allow drivers, and plugins to declare that certain routes must never be proxied
MODIFY
packages/base-driver/lib/protocol/protocol.js
packages/base-driver/lib/protocol/protocol.js
@@ -231,13 +231,15 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
throw new errors.NoSuchDriverError();
}
- // if the driver is currently proxying commands to another JSONWP
- // server, bypass all our checks and assume the upstream server knows
- // what it's doing. But keep this in the try/catch block so if proxying
- // itself fails, we give a message to the client. Of course we only
- // want to do these when we have a session command; the Appium driver
- // must be responsible for start/stop session, etc...
- if (isSessCmd && driverShouldDoJwpProxy(driver, req, spec.command)) {
+ // if the driver is currently proxying commands to another JSONWP server, bypass all our
+ // checks and assume the upstream server knows what it's doing. But keep this in the
+ // try/catch block so if proxying itself fails, we give a message to the client. Of course we
+ // only want to do these when we have a session command; the Appium driver must be
+ // responsible for start/stop session, etc... We also allow the command spec to declare that
+ // this command should never be proxied (which is useful for plugin developers who add
+ // commands and generally would not want that command to be proxied instead of handled by the
+ // plugin)
+ if (isSessCmd && !spec.neverProxy && driverShouldDoJwpProxy(driver, req, spec.command)) {
await doJwpProxy(driver, req, res);
return;
}

MODIFY
packages/base-driver/test/protocol/fake-driver.js
packages/base-driver/test/protocol/fake-driver.js
@@ -6,6 +6,12 @@ import { util } from '@appium/support';
class FakeDriver extends BaseDriver {
+ static newMethodMap = {
+ '/session/:sessionId/noproxy': {
+ GET: {command: 'notProxiedCommand', neverProxy: true}
+ }
+ };
+
constructor () {
super();
this.protocol = PROTOCOLS.MJSONWP;
@@ -131,6 +137,10 @@ class FakeDriver extends BaseDriver {
canProxy (/*sessionId*/) {
return false;
}
+
+ async notProxiedCommand () {
+ return 'This was not proxied';
+ }
}
export { FakeDriver };

MODIFY
packages/base-driver/test/protocol/protocol-e2e-specs.js
packages/base-driver/test/protocol/protocol-e2e-specs.js
@@ -900,6 +900,7 @@ describe('Protocol', function () {
mjsonwpServer = await server({
routeConfiguringFunction: routeConfiguringFunction(driver),
port,
+ extraMethodMap: FakeDriver.newMethodMap
});
});
@@ -1053,5 +1054,20 @@ describe('Protocol', function () {
should.not.exist(driver.sessionId);
driver.jwpProxyActive.should.be.false;
});
+
+ it('should avoid proxying when command spec specifies neverProxy', async function () {
+ const {status, data} = await axios({
+ url: `${baseUrl}/session/${sessionId}/noproxy`,
+ method: 'GET',
+ });
+
+ status.should.equal(200);
+ data.should.eql({
+ status: 0,
+ value: 'This was not proxied',
+ sessionId
+ });
+ });
+
});
});

feat(base-driver): allow drivers, and plugins to declare that certain routes must never be proxied