elasticio-sailor-nodejs 3.0.0-sailor-proxy-dev4 → 3.0.0-sailor-proxy-dev5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/proxy-client.js +16 -14
- package/package.json +1 -1
package/lib/proxy-client.js
CHANGED
|
@@ -495,14 +495,23 @@ class ProxyClient {
|
|
|
495
495
|
this.listeningForMessages = false;
|
|
496
496
|
}
|
|
497
497
|
|
|
498
|
-
|
|
499
|
-
|
|
498
|
+
_prepareData(data, headers, type) {
|
|
499
|
+
const proxyHeaders = this._createProxyHeaders(headers);
|
|
500
|
+
let protocolVersion;
|
|
500
501
|
if (type === 'data') {
|
|
501
502
|
protocolVersion = this.settings.PROTOCOL_VERSION;
|
|
502
503
|
} else if (type === 'http-reply') {
|
|
503
504
|
protocolVersion = 1;
|
|
504
505
|
}
|
|
505
|
-
|
|
506
|
+
let preparedData;
|
|
507
|
+
if (protocolVersion) {
|
|
508
|
+
preparedData = this.encryptMessageContent(data, protocolVersion);
|
|
509
|
+
proxyHeaders.protocolVersion = protocolVersion;
|
|
510
|
+
}
|
|
511
|
+
return {
|
|
512
|
+
preparedData,
|
|
513
|
+
proxyHeaders
|
|
514
|
+
};
|
|
506
515
|
}
|
|
507
516
|
|
|
508
517
|
async sendMessage({
|
|
@@ -521,14 +530,9 @@ class ProxyClient {
|
|
|
521
530
|
|
|
522
531
|
log.debug({ incomingMessageId, type, headers }, 'Sending message to proxy');
|
|
523
532
|
log.trace({ data }, 'Message data to send to proxy');
|
|
524
|
-
const proxyHeaders = this.
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
// payload again (see `sendError` method) - we just stringify it. For other message types, we encrypt
|
|
528
|
-
// the content before sending.
|
|
529
|
-
const encryptedData = type === 'error' ? data : this.encryptMessageContent(data, protocolVersion);
|
|
530
|
-
if (encryptedData.length > this.settings.OUTGOING_MESSAGE_SIZE_LIMIT) {
|
|
531
|
-
const error = new Error(`Outgoing message size ${encryptedData.length}`
|
|
533
|
+
const { proxyHeaders, preparedData } = this._prepareData(data, headers, type);
|
|
534
|
+
if (preparedData.length > this.settings.OUTGOING_MESSAGE_SIZE_LIMIT) {
|
|
535
|
+
const error = new Error(`Outgoing message size ${preparedData.length}`
|
|
532
536
|
+ ` exceeds limit of ${this.settings.OUTGOING_MESSAGE_SIZE_LIMIT}.`);
|
|
533
537
|
log.error(error);
|
|
534
538
|
throw error;
|
|
@@ -550,7 +554,7 @@ class ProxyClient {
|
|
|
550
554
|
[HTTP2_HEADER_METHOD]: 'POST',
|
|
551
555
|
[HTTP2_HEADER_AUTHORIZATION]: this.authHeader
|
|
552
556
|
});
|
|
553
|
-
postMessageStream.write(
|
|
557
|
+
postMessageStream.write(preparedData);
|
|
554
558
|
postMessageStream.end();
|
|
555
559
|
|
|
556
560
|
postMessageStream.on('response', (headers) => {
|
|
@@ -667,8 +671,6 @@ class ProxyClient {
|
|
|
667
671
|
async sendError(err, headers, originalMessage, incomingHeaders) {
|
|
668
672
|
await this._ensureConnection();
|
|
669
673
|
|
|
670
|
-
const settings = this.settings;
|
|
671
|
-
|
|
672
674
|
const encryptedError = this._encryptor.encryptMessageContent({
|
|
673
675
|
name: err.name,
|
|
674
676
|
message: err.message,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elasticio-sailor-nodejs",
|
|
3
3
|
"description": "The official elastic.io library for bootstrapping and executing for Node.js connectors",
|
|
4
|
-
"version": "3.0.0-sailor-proxy-
|
|
4
|
+
"version": "3.0.0-sailor-proxy-dev5",
|
|
5
5
|
"main": "run.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|