@contrast/instrumentation 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/lib/http2.js +29 -25
  2. package/package.json +2 -2
package/lib/http2.js CHANGED
@@ -20,35 +20,39 @@ module.exports = function(core) {
20
20
  depHooks
21
21
  } = core;
22
22
 
23
+ function createPostHook(namePrefix, patchType, methods, around) {
24
+ return function post(data) {
25
+ const { result: server } = data;
26
+ const serverPrototype = server ? Object.getPrototypeOf(server) : null;
27
+
28
+ if (!serverPrototype) {
29
+ core.logger.error('Unable to patch server prototype, continue without instrumentation');
30
+ return;
31
+ }
32
+ methods.forEach((method) => {
33
+ patcher.patch(serverPrototype, method, {
34
+ name: `${namePrefix}.${method}`,
35
+ patchType,
36
+ around
37
+ });
38
+ });
39
+ };
40
+ }
41
+
23
42
  return {
24
43
  'http2'(opts) {
25
44
  depHooks.resolve({ name: 'http2' }, (http2) => {
26
- opts.patchObjects.forEach((obj) => {
27
- const { methods, patchType, patchObjects } = obj;
28
- methods.forEach((method) => {
29
- patcher.patch(http2, method, {
30
- name: `http2.${method}`,
31
- patchType,
32
- post(data) {
33
- const { result: server } = data;
34
- const serverPrototype = server ? Object.getPrototypeOf(server) : null;
45
+ opts.patchObjects.forEach(({ methods, patchType, around }) => {
46
+ patcher.patch(http2, 'createServer', {
47
+ name: 'http2.createServer',
48
+ patchType,
49
+ post: createPostHook('http2.Server.prototype', patchType, methods, around),
50
+ });
35
51
 
36
- if (!serverPrototype) {
37
- core.logger.error('Unable to patch server prototype, continue without instrumentation');
38
- return;
39
- }
40
- patchObjects.forEach((obj) => {
41
- const { name, methods, patchType, around } = obj;
42
- methods.forEach((method) => {
43
- patcher.patch(serverPrototype, method, {
44
- name: `http2.${name}.${method}`,
45
- patchType,
46
- around
47
- });
48
- });
49
- });
50
- }
51
- });
52
+ patcher.patch(http2, 'createSecureServer', {
53
+ name: 'http2.createSecureServer',
54
+ patchType,
55
+ post: createPostHook('http2.SecureServer.prototype', patchType, methods, around)
52
56
  });
53
57
  });
54
58
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/instrumentation",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Shared hooks and patches between Protect and Assess components",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -16,4 +16,4 @@
16
16
  "scripts": {
17
17
  "test": "../scripts/test.sh"
18
18
  }
19
- }
19
+ }