whistle.script 1.2.2 → 1.2.6

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/util.js CHANGED
@@ -2,6 +2,7 @@ const zlib = require('zlib');
2
2
  const { EventEmitter } = require('events');
3
3
  const { parse: parseUrl } = require('url');
4
4
  const http = require('http');
5
+ const https = require('https');
5
6
  const dataSource = require('./dataSource');
6
7
 
7
8
  exports.AUTH_URL = 'x-whistle-.script-auth-url';
@@ -14,7 +15,7 @@ exports.noop = () => {};
14
15
 
15
16
  const POLICY = 'x-whistle-.script-policy';
16
17
  const isFunction = fn => typeof fn === 'function';
17
- const URL_RE = /^http:(?:\/\/|%3A%2F%2F)[\w.-]/;
18
+ const URL_RE = /^https?:(?:\/\/|%3A%2F%2F)[\w.-]/;
18
19
 
19
20
  exports.isFunction = isFunction;
20
21
  exports.noop = () => {};
@@ -141,7 +142,9 @@ const request = (url, headers, data) => {
141
142
  options.method = 'POST';
142
143
  }
143
144
  return new Promise((resolve, reject) => {
144
- const client = http.request(options, (res) => {
145
+ const httpModule = options.protocol === 'https:' ? https : http;
146
+ options.rejectUnauthorized = false;
147
+ const client = httpModule.request(options, (res) => {
145
148
  res.on('error', handleError); // eslint-disable-line
146
149
  let body;
147
150
  res.on('data', (chunk) => {
package/lib/wsServer.js CHANGED
@@ -3,6 +3,17 @@ const iconv = require('iconv-lite');
3
3
  const { getDataSource, getFn } = require('./util');
4
4
  const scripts = require('./scripts');
5
5
 
6
+ const toBuffer = (data) => {
7
+ if (Buffer.isBuffer(data)) {
8
+ return data;
9
+ }
10
+ if (data == null) {
11
+ data = '';
12
+ } else if (typeof data !== 'string') {
13
+ data = JSON.stringify(data);
14
+ }
15
+ return data && Buffer.from(data);
16
+ };
6
17
 
7
18
  module.exports = (server, options) => {
8
19
  const { getReceiver, getSender } = options.wsParser;
@@ -18,7 +29,13 @@ module.exports = (server, options) => {
18
29
  err.code = code;
19
30
  socket.emit('error', err);
20
31
  };
21
- socket.send = sender.send.bind(sender);
32
+ socket.send = (data, opts, cb) => {
33
+ try {
34
+ return sender.send(toBuffer(data), opts, cb);
35
+ } catch (e) {
36
+ socket.emit('error', e);
37
+ }
38
+ };
22
39
  socket.ping = sender.ping.bind(sender);
23
40
  socket.pong = sender.pong.bind(sender);
24
41
  socket.disconnect = sender.close.bind(sender);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "whistle.script",
3
3
  "description": "The plugin for the extension script for whistle",
4
- "version": "1.2.2",
4
+ "version": "1.2.6",
5
5
  "author": "avenwu <avenwu@vip.qq.com>",
6
6
  "contributors": [],
7
7
  "license": "MIT",
@@ -15,6 +15,9 @@
15
15
  "ssi"
16
16
  ],
17
17
  "registry": "https://github.com/whistle-plugins/whistle.script",
18
+ "whistleConfig": {
19
+ "pluginVars": true
20
+ },
18
21
  "repository": {
19
22
  "type": "git",
20
23
  "url": "https://github.com/whistle-plugins/whistle.script.git"
package/rules.txt CHANGED
@@ -1,2 +1,2 @@
1
- * whistle.script:// includeFilter://reqH.x-whistle-.script-policy=remote
2
- * sniCallback://script includeFilter://reqH.x-whistle-.script-policy=sni
1
+ * whistle.script:// delete://reqH.x-whistle-.script-policy|reqH.x-whistle-.script-auth-url|reqH.x-whistle-.script-req-rules-url|reqH.x-whistle-.script-res-rules-url|reqH.x-whistle-.script-stats-url|reqH.x-whistle-.script-data-url includeFilter://reqH.x-whistle-.script-policy=remote
2
+ * sniCallback://script delete://reqH.x-whistle-.script-policy|reqH.x-whistle-.script-sni-url includeFilter://reqH.x-whistle-.script-policy=sni