Skip to content

chore: replace request by got #88

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ node_modules

# Optional REPL history
.node_repl_history

.idea/
yarn.lock
54 changes: 22 additions & 32 deletions lib/apicontrollersbase.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

var request = require('request');
var got = require('got');
var logger = require('./logger.js').logger;
var config = require('./config').config;
var constants = require('./constants').constants;
var hpagent = require('hpagent');

class APIOperationBase {
constructor(apiRequest) {
Expand Down Expand Up @@ -80,43 +81,32 @@ class APIOperationBase {

logger.debug(JSON.stringify(this._request, 2, null));

var reqOpts = {
url: this._endpoint,
method: 'POST',
json: true,
timeout: config.timeout,
body: this._request
};
var reqOpts = { timeout: config.timeout, json: this._request, method: 'POST' };

if(config.proxy.setProxy){
reqOpts['proxy'] = config.proxy.proxyUrl;
if (config.proxy.setProxy) {
reqOpts['agent'] = {
https: new hpagent.HttpsProxyAgent({
proxy: config.proxy.proxyUrl
})
};
}

request(reqOpts, function(error, response, body){
if(error) {
logger.error(error);
} else
{
//TODO: slice added due to BOM character. remove once BOM character is removed.
if(typeof body!=='undefined'){
var responseObj = JSON.parse(body.slice(1));
got(this._endpoint, reqOpts)
.then(response => {
const body = response.body;
// TODO: slice added due to BOM character. remove once BOM character is removed.
if (typeof body !== 'undefined') {
const responseObj = JSON.parse(body.slice(1));
logger.debug(JSON.stringify(responseObj, 2, null));
obj._response = responseObj;
/*
var jsonResponse = JSON.stringify(body);
console.log("escaped body : '" + escape(jsonResponse) + "'");
console.log("body : '" + jsonResponse + "'");
logger.debug("Response: " + JSON.stringify(body, 2, null));
obj._response = body;
*/
callback();
}
else
{
logger.error("Undefined Response");
callback();
} else {
logger.error('Undefined Response');
}
}
});
})
.catch(error => {
logger.error(error);
});

logger.debug('Exit APIOperationBase execute');
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test": "tests"
},
"dependencies": {
"request": "^2.72.0",
"got": "^13.0.0",
"hpagent": "^1.2.0",
"winston": "^2.2.0"
},
"devDependencies": {
Expand Down