Skip to content

Commit

Permalink
fix: HTTP transport should take a URL (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
abmusse committed Apr 22, 2020
1 parent 60e19e3 commit 34e4e37
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 1 addition & 3 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ const availableTransports = {
* @property {string} [database=*LOCAL] - The database to connect to. Default is ``*LOCAL``.
* @property {string} username - The user to connect as.
* @property {string} password - The user's password.
* @property {string} [host=localhost] - The hostname of the server. Default is ``localhost``.
* @property {string} [ipc=*NA] - The key name/security route to XMLSERVICE job. Default is ``*NA``.
* @property {string} [ctl=*here] - The control options for XMLSERVICE jobs. Default is ``*here``.
* @property {number} port=80 - The port on the server. Default is ``80``.
* @property {string} path=/ - The path to xmlcgi endpoint. Default is ``/``.
* @property {string} url - The url to the xmlcgi endpoint. E.g. ``http://localhost:80/cgi-bin/xmlcgi.pgm``
*/

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,9 @@ class iConn {
// pre v1.0 falls back to idb transport when host is not specified
if (option.host) {
options.transport = 'rest';
// construct the url host:port/path
options.transportOptions.url = `http://${option.host}:${option.port || 80}${option.path || '/'}`;
}
options.transportOptions = { ...options.transportOptions, ...option };
}

this.connection = new Connection(options);
Expand Down
14 changes: 7 additions & 7 deletions lib/transports/httpTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ const httpCall = (config, xmlInput, done) => {
password = null,
ipc = '*NA',
ctl = '*here',
host = 'localhost',
port = 80,
path = '/',
url = null,
} = config;

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

if (!url || typeof url !== 'string') {
done('Provide a valid url', null);
return;
}

const parms = {
db2: database,
uid: username,
Expand All @@ -58,17 +61,14 @@ const httpCall = (config, xmlInput, done) => {
const queryString = Object.keys(parms).map((k) => `${k}=${encodeURIComponent(parms[k])}`).join('&');

const options = {
host,
port,
path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(queryString),
},
};

const request = http.request(options, (response) => {
const request = http.request(url, options, (response) => {
let xmlOutput = '';

response.on('data', (chunk) => {
Expand Down
2 changes: 2 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Functional tests can be configured using the following enviornment variables.

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

- `TKURL` - The url to the xmlcgi endpoint.

- `TKPK` - The path to a private key file when using `ssh` transport.

- `TKPHRASE` - The passphrase to decrypt the private key.
Expand Down
1 change: 1 addition & 0 deletions test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const config = {
host: process.env.TKHOST || 'localhost',
port: process.env.TKPORT,
path: process.env.TKPATH || '/cgi-bin/xmlcgi.pgm',
url: process.env.TKURL,
privateKey,
// passphrase is used by the ssh transport to decrypt the private key
passphrase: process.env.TKPHRASE,
Expand Down

0 comments on commit 34e4e37

Please sign in to comment.