Skip to content
Snippets Groups Projects
Commit 2faa1164 authored by Rolf Niepraschk's avatar Rolf Niepraschk
Browse files

Tst zu "request" --> "axios"

parent e16949a6
No related branches found
No related tags found
No related merge requests found
http1.js 0 → 100644
/**
* @author Rolf Niepraschk (Rolf.Niepraschk@ptb.de)
* version: 2020-04-27
*/
const cfg = require('./config.js');
const tools = require('./tools.js');
const utils = require('./utils.js');
const axios = require('axios');
const response = require('./response.js');
const logger = cfg.logger;
/**
* Konfiguration der nötigen Datenstrukturen und Aufnahme der HTTP-Kommunikation.
* Wait/Repeat wird derzeit nicht unterstützt. Die Umgebungsvariablen proxy und
* no_proxy werden berücksichtigt.
* @param {object} pRef interne Serverdaten (req, res, ...)
* @param {object} js empfangene JSON-Struktur um weitere Daten ergänzt
*/
function call(pRef, js) {
var method = js.Method || 'get';
const json = typeof js.Json == 'boolean' ? js.Json : false;
const timeout = js.Timeout || 0;
const noProxy = typeof js.NoProxy == 'boolean' ? js.NoProxy : false;
const responseType = js.ResponseType ? js.ResponseType : json ? 'json' : 'text';
// TODO: "js.Header" ???
if (!js.Method) {
if (js.Body) {
if (typeof js.Body != 'string' && typeof js.Body != 'Buffer' && !json) {
response.prepareError(pRef, js,
"Wrong type of Body. (Missing 'Json:true'?)");
return;
}
method = 'post';
} else {
method = 'get';
}
}
logger.debug("************************************************");
logger.debug(`method: ${method}, json: ${json}, timeout: ${timeout}, noProxy: ${noProxy}`);
utils.addStartTime(js);
var config = {};
config.url = js.Url;
config.method = method.toLowerCase()
config.timeout = timeout;
if (js.Body) config.data = js.Body;
config.responseType = responseType;
if (noProxy) config.proxy = false;
axios(config)
.then(function (res) {
if (res.status > 199 && res.status < 300) {
utils.addStopTime(js);
logger.debug('response body: ', res.data);
response.prepareResult(pRef, js, res.data);
} else {
const x = res.statusText || res.status ? res.status : 'unknown error';
logger.error(x);
response.prepareError(pRef, js, x);
}
})
.catch(function (error) {
var x;
if (error.response) {
const e = error.response;
x = e.statusText || e.status ? e.status : 'unknown error';
} else if (error.request) {
x = error.request; // ???
} else {
x = error.message;
}
logger.error(x);
response.prepareError(pRef, js, x);
});
}
exports.call = call;
......@@ -10,7 +10,7 @@ var utils = require('./utils.js');
var response = require('./response.js');
var _tcp = require('./tcp.js');
var _udp = require('./udp.js');
var _http = require('./http.js');
var _http = require('./http1.js');
var _email = require('./email.js');
//var _ldap = require('./ldap.js');
// derzeit (2013-01-14) Probleme (buffertools)!
......
{
"name": "relayServer",
"version": "13.1.0",
"version": "13.1.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -143,6 +143,14 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
},
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"requires": {
"follow-redirects": "1.5.10"
}
},
"backo2": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
......@@ -706,6 +714,29 @@
"is-buffer": "~2.0.3"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
"forever-agent": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
......
......@@ -18,6 +18,7 @@
"test-rolf-inst": "env TESTHOST=i75434.berlin.ptb.de npm run test"
},
"dependencies": {
"axios": "^0.19.2",
"bunyan": "^1.8.12",
"bunyan-debug-stream": "^2.0.0",
"bunyan-gelf": ">=1.0.0",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment