@nxtedition/lib 15.0.35 → 15.0.36

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/package.json +2 -6
  2. package/proxy.js +0 -106
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "15.0.35",
3
+ "version": "15.0.36",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "files": [
@@ -72,7 +72,6 @@
72
72
  "/__tests__"
73
73
  ],
74
74
  "dependencies": {
75
- "cache-control-parser": "^2.0.4",
76
75
  "date-fns": "^2.29.3",
77
76
  "fast-querystring": "^1.1.1",
78
77
  "hasha": "^5.2.2",
@@ -80,13 +79,11 @@
80
79
  "json5": "^2.2.3",
81
80
  "koa-compose": "^4.1.0",
82
81
  "lodash": "^4.17.21",
83
- "lru-cache": "^10.0.1",
84
82
  "mime": "^3.0.0",
85
83
  "moment-timezone": "^0.5.43",
86
84
  "nconf": "^0.12.0",
87
85
  "nested-error-stacks": "^2.1.1",
88
86
  "object-hash": "^3.0.0",
89
- "omit-empty": "^1.0.0",
90
87
  "pino-std-serializers": "^6.2.2",
91
88
  "qs": "^6.11.1",
92
89
  "request-target": "^1.0.2",
@@ -94,8 +91,7 @@
94
91
  "split-string": "^6.0.0",
95
92
  "toobusy-js": "^0.5.1",
96
93
  "undici": "^5.25.4",
97
- "url-join": "^4.0.0",
98
- "xuid": "^4.1.2"
94
+ "url-join": "^4.0.0"
99
95
  },
100
96
  "devDependencies": {
101
97
  "@types/node": "^20.8.2",
package/proxy.js DELETED
@@ -1,106 +0,0 @@
1
- const createError = require('http-errors')
2
- const net = require('net')
3
-
4
- // This expression matches hop-by-hop headers.
5
- // These headers are meaningful only for a single transport-level connection,
6
- // and must not be retransmitted by proxies or cached.
7
- const HOP_EXPR =
8
- /^(te|host|upgrade|trailers|connection|keep-alive|http2-settings|transfer-encoding|proxy-connection|proxy-authenticate|proxy-authorization)$/i
9
-
10
- // Removes hop-by-hop and pseudo headers.
11
- // Updates via and forwarded headers.
12
- // Only hop-by-hop headers may be set using the Connection general header.
13
- module.exports.reduceHeaders = function reduceHeaders(
14
- { id, headers, proxyName, httpVersion, socket },
15
- fn,
16
- acc,
17
- ) {
18
- let via
19
- let forwarded
20
- let host
21
- let authority
22
- let connection
23
-
24
- const entries = Object.entries(headers)
25
-
26
- for (const [key, val] of entries) {
27
- const len = key.length
28
- if (len === 3 && !via && key.toLowerCase() === 'via') {
29
- via = val
30
- } else if (len === 4 && !host && key.toLowerCase() === 'host') {
31
- host = val
32
- } else if (len === 9 && !forwarded && key.toLowerCase() === 'forwarded') {
33
- forwarded = val
34
- } else if (len === 10 && !connection && key.toLowerCase() === 'connection') {
35
- connection = val
36
- } else if (len === 10 && !authority && key.toLowerCase() === ':authority') {
37
- authority = val
38
- }
39
- }
40
-
41
- let remove
42
- if (connection && !HOP_EXPR.test(connection)) {
43
- remove = connection.split(/,\s*/)
44
- }
45
-
46
- for (const [key, val] of entries) {
47
- if (key.charAt(0) !== ':' && !remove?.includes(key) && !HOP_EXPR.test(key)) {
48
- acc = fn(acc, key, val)
49
- }
50
- }
51
-
52
- if (socket) {
53
- const forwardedHost = authority || host
54
- acc = fn(
55
- acc,
56
- 'forwarded',
57
- (forwarded ? forwarded + ', ' : '') +
58
- [
59
- socket.localAddress && `by=${printIp(socket.localAddress, socket.localPort)}`,
60
- socket.remoteAddress && `for=${printIp(socket.remoteAddress, socket.remotePort)}`,
61
- `proto=${socket.encrypted ? 'https' : 'http'}`,
62
- forwardedHost && `host="${forwardedHost}"`,
63
- ].join(';'),
64
- )
65
- } else if (forwarded) {
66
- // The forwarded header should not be included in response.
67
- throw new createError.BadGateway()
68
- }
69
-
70
- if (proxyName) {
71
- if (via) {
72
- if (via.split(',').some((name) => name.endsWith(proxyName))) {
73
- throw new createError.LoopDetected()
74
- }
75
- via += ', '
76
- } else {
77
- via = ''
78
- }
79
- via += `${httpVersion} ${proxyName}`
80
- }
81
-
82
- if (via) {
83
- acc = fn(acc, 'via', via)
84
- }
85
-
86
- if (id) {
87
- acc = fn(acc, 'request-id', id)
88
- }
89
-
90
- return acc
91
- }
92
-
93
- function printIp(address, port) {
94
- const isIPv6 = net.isIPv6(address)
95
- let str = `${address}`
96
- if (isIPv6) {
97
- str = `[${str}]`
98
- }
99
- if (port) {
100
- str = `${str}:${port}`
101
- }
102
- if (isIPv6 || port) {
103
- str = `"${str}"`
104
- }
105
- return str
106
- }