blob: 89a0ac4d8b977c28c3e71916ddb4d793dc59b11b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
'use strict';
const {ERR_HTTP2_NO_SOCKET_MANIPULATION} = require('./errors.js');
/* istanbul ignore file */
/* https://github.com/nodejs/node/blob/6eec858f34a40ffa489c1ec54bb24da72a28c781/lib/internal/http2/compat.js#L195-L272 */
const proxySocketHandler = {
has(stream, property) {
// Replaced [kSocket] with .socket
const reference = stream.session === undefined ? stream : stream.session.socket;
return (property in stream) || (property in reference);
},
get(stream, property) {
switch (property) {
case 'on':
case 'once':
case 'end':
case 'emit':
case 'destroy':
return stream[property].bind(stream);
case 'writable':
case 'destroyed':
return stream[property];
case 'readable':
if (stream.destroyed) {
return false;
}
return stream.readable;
case 'setTimeout': {
const {session} = stream;
if (session !== undefined) {
return session.setTimeout.bind(session);
}
return stream.setTimeout.bind(stream);
}
case 'write':
case 'read':
case 'pause':
case 'resume':
throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
default: {
// Replaced [kSocket] with .socket
const reference = stream.session === undefined ? stream : stream.session.socket;
const value = reference[property];
return typeof value === 'function' ? value.bind(reference) : value;
}
}
},
getPrototypeOf(stream) {
if (stream.session !== undefined) {
// Replaced [kSocket] with .socket
return Reflect.getPrototypeOf(stream.session.socket);
}
return Reflect.getPrototypeOf(stream);
},
set(stream, property, value) {
switch (property) {
case 'writable':
case 'readable':
case 'destroyed':
case 'on':
case 'once':
case 'end':
case 'emit':
case 'destroy':
stream[property] = value;
return true;
case 'setTimeout': {
const {session} = stream;
if (session === undefined) {
stream.setTimeout = value;
} else {
session.setTimeout = value;
}
return true;
}
case 'write':
case 'read':
case 'pause':
case 'resume':
throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
default: {
// Replaced [kSocket] with .socket
const reference = stream.session === undefined ? stream : stream.session.socket;
reference[property] = value;
return true;
}
}
}
};
module.exports = proxySocketHandler;
|