elasticio-sailor-nodejs 3.0.0-sailor-proxy-dev4 → 3.0.0-sailor-proxy-dev6
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 +17 -15
- 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
|
-
let protocolVersion
|
|
498
|
+
_prepareData(data, headers, type) {
|
|
499
|
+
let protocolVersion;
|
|
500
500
|
if (type === 'data') {
|
|
501
501
|
protocolVersion = this.settings.PROTOCOL_VERSION;
|
|
502
502
|
} else if (type === 'http-reply') {
|
|
503
503
|
protocolVersion = 1;
|
|
504
504
|
}
|
|
505
|
-
|
|
505
|
+
let preparedData;
|
|
506
|
+
if (protocolVersion) {
|
|
507
|
+
preparedData = this.encryptMessageContent(data, protocolVersion);
|
|
508
|
+
proxyHeaders.protocolVersion = protocolVersion;
|
|
509
|
+
}
|
|
510
|
+
const proxyHeaders = this._createProxyHeaders({ ...headers, protocolVersion });
|
|
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) => {
|
|
@@ -600,7 +604,7 @@ class ProxyClient {
|
|
|
600
604
|
_decodeErrorMessage(originalMessage, headers) {
|
|
601
605
|
const errorBody = JSON.parse(originalMessage.toString());
|
|
602
606
|
// NOTICE both error and errorInput are transferred as base64 encoded.
|
|
603
|
-
// this does not depend on protocolVersion header of message (see
|
|
607
|
+
// this does not depend on protocolVersion header of message (see _decodeDefaultMessage)
|
|
604
608
|
// this should be fixed in future, but it's OK at this moment
|
|
605
609
|
if (errorBody.error) {
|
|
606
610
|
errorBody.error = this._encryptor.decryptMessageContent(Buffer.from(errorBody.error), 'base64');
|
|
@@ -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-dev6",
|
|
5
5
|
"main": "run.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|