Files
appium/packages/base-driver/lib/jsonwp-proxy
Kazuaki Matsuo 7edd3bdc11 chore: use RegExp to check session id requirement (#20947)
* chore: use regext to check session id requirement

* update docs

* add test case

* use match of path-to-regexp

* use another name to avoid conflict

* accept appium prefix for non-session id
2025-02-01 01:03:15 -08:00
..

appium-jsonwp-proxy

Proxy middleware for the Selenium JSON Wire Protocol. Allows

Usage

The proxy is used by instantiating with the details of the Selenium server to which to proxy. The options for the constructor are passed as a hash with the following possible members:

  • scheme - defaults to 'http'
  • server - defaults to 'localhost'
  • port - defaults to 4444
  • base - defaults to ''
  • sessionId - the session id of the session on the remote server
  • reqBasePath - the base path of the server which the request was originally sent to (defaults to '')

Once the proxy is created, there are two async methods:

command (url, method, body)

Sends a "command" to the proxied server, using the "url", which is the endpoing, with the HTTP method and optional body.

import { JWProxy } from 'appium-base-driver';

let host = 'my.host.com';
let port = 4445;

let proxy = new JWProxy({server: host, port: port});

// get the Selenium server status
let seStatus = await proxy.command('/status', 'GET');

proxyReqRes (req, res)

Proxies a request and response to the proxied server. Used to handle the entire conversation of a request/response cycle.

import { JWProxy } from 'appium-base-driver';
import http from 'http';

let host = 'my.host.com';
let port = 4445;

let proxy = new JWProxy({server: host, port: port});


http.createServer(function (req, res) {
  await proxy.proxyReqRes(res, res);
}).listen(9615);