Skip to content

fix: HTTP transport should take a URL #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this change is the cause of unit test failure. We should still append user passed options to the transportOptions like we did before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. I should have caught that.

}

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