Skip to content

Commit 34e4e37

Browse files
authored
fix: HTTP transport should take a URL (#252)
1 parent 60e19e3 commit 34e4e37

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

lib/Connection.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ const availableTransports = {
6666
* @property {string} [database=*LOCAL] - The database to connect to. Default is ``*LOCAL``.
6767
* @property {string} username - The user to connect as.
6868
* @property {string} password - The user's password.
69-
* @property {string} [host=localhost] - The hostname of the server. Default is ``localhost``.
7069
* @property {string} [ipc=*NA] - The key name/security route to XMLSERVICE job. Default is ``*NA``.
7170
* @property {string} [ctl=*here] - The control options for XMLSERVICE jobs. Default is ``*here``.
72-
* @property {number} port=80 - The port on the server. Default is ``80``.
73-
* @property {string} path=/ - The path to xmlcgi endpoint. Default is ``/``.
71+
* @property {string} url - The url to the xmlcgi endpoint. E.g. ``http://localhost:80/cgi-bin/xmlcgi.pgm``
7472
*/
7573

7674
/**

lib/Deprecated.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,9 @@ class iConn {
564564
// pre v1.0 falls back to idb transport when host is not specified
565565
if (option.host) {
566566
options.transport = 'rest';
567+
// construct the url host:port/path
568+
options.transportOptions.url = `http://${option.host}:${option.port || 80}${option.path || '/'}`;
567569
}
568-
options.transportOptions = { ...options.transportOptions, ...option };
569570
}
570571

571572
this.connection = new Connection(options);

lib/transports/httpTransport.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ const httpCall = (config, xmlInput, done) => {
2424
password = null,
2525
ipc = '*NA',
2626
ctl = '*here',
27-
host = 'localhost',
28-
port = 80,
29-
path = '/',
27+
url = null,
3028
} = config;
3129

3230
// perform some validation
@@ -45,6 +43,11 @@ const httpCall = (config, xmlInput, done) => {
4543
return;
4644
}
4745

46+
if (!url || typeof url !== 'string') {
47+
done('Provide a valid url', null);
48+
return;
49+
}
50+
4851
const parms = {
4952
db2: database,
5053
uid: username,
@@ -58,17 +61,14 @@ const httpCall = (config, xmlInput, done) => {
5861
const queryString = Object.keys(parms).map((k) => `${k}=${encodeURIComponent(parms[k])}`).join('&');
5962

6063
const options = {
61-
host,
62-
port,
63-
path,
6464
method: 'POST',
6565
headers: {
6666
'Content-Type': 'application/x-www-form-urlencoded',
6767
'Content-Length': Buffer.byteLength(queryString),
6868
},
6969
};
7070

71-
const request = http.request(options, (response) => {
71+
const request = http.request(url, options, (response) => {
7272
let xmlOutput = '';
7373

7474
response.on('data', (chunk) => {

test/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Functional tests can be configured using the following enviornment variables.
3838

3939
- `TKPATH` - The path to xmlcgi. Defaults to `/cgi-bin/xmlcgi.pgm`
4040

41+
- `TKURL` - The url to the xmlcgi endpoint.
42+
4143
- `TKPK` - The path to a private key file when using `ssh` transport.
4244

4345
- `TKPHRASE` - The passphrase to decrypt the private key.

test/functional/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const config = {
1515
host: process.env.TKHOST || 'localhost',
1616
port: process.env.TKPORT,
1717
path: process.env.TKPATH || '/cgi-bin/xmlcgi.pgm',
18+
url: process.env.TKURL,
1819
privateKey,
1920
// passphrase is used by the ssh transport to decrypt the private key
2021
passphrase: process.env.TKPHRASE,

0 commit comments

Comments
 (0)