Commit 8d0c638
lib: support overriding http\s.globalAgent
Overriding `require('http[s]').globalAgent` is now respected by
consequent requests.
In order to achieve that, the following changes were made:
1. Implmentation in `http`: `module.exports.globalAgent` is now defined
through `Object.defineProperty`. Its getter and setter return \ set
`require('_http_agent').globalAgent`.
2. Implementation in `https`: the https `globalAgent` is not the same
as `_http_agent`, and is defined in `https` module itself. Therefore,
the fix here was to simply use `module.exports.globalAgent` to support
mutation.
3. According tests were added for both `http` and `https`, where in
both we create a server, set the default agent to a newly created
instance and make a request to that server. We then assert that the
given instance was actually used by inspecting its sockets property.
Fixes: #23281
PR-URL: #25170
Reviewed-By: James M Snell <jasnell@gmail.com>1 parent ce7bbd2 commit 8d0c638Copy full SHA for 8d0c638
File tree
Expand file treeCollapse file tree
4 files changed
+78
-4
lines changedOpen diff view settings
Filter options
- lib
- test/parallel
Expand file treeCollapse file tree
4 files changed
+78
-4
lines changedOpen diff view settings
Collapse file
+13-3Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | | - |
| 24 | + |
25 | 25 | |
26 | 26 | |
27 | 27 | |
| ||
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | | - |
| 55 | + |
56 | 56 | |
57 | | - |
58 | 57 | |
59 | 58 | |
60 | 59 | |
| ||
76 | 75 | |
77 | 76 | |
78 | 77 | |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
Collapse file
+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
294 | 294 | |
295 | 295 | |
296 | 296 | |
297 | | - |
| 297 | + |
298 | 298 | |
299 | 299 | |
300 | 300 | |
|
Collapse file
test/parallel/test-http-client-override-global-agent.js
Copy file name to clipboard+26Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 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 | + |
Collapse file
test/parallel/test-https-client-override-global-agent.js
Copy file name to clipboard+38Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 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 | + |
0 commit comments