@fastify/reply-from 8.4.1 → 8.4.3
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/index.js +1 -1
- package/lib/request.js +2 -2
- package/lib/utils.js +0 -26
- package/package.json +2 -2
- package/test/host-header.js +7 -1
package/index.js
CHANGED
|
@@ -74,7 +74,7 @@ const fastifyReplyFrom = fp(function from (fastify, opts, next) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
const sourceHttp2 = req.httpVersionMajor === 2
|
|
77
|
-
const headers = sourceHttp2 ? filterPseudoHeaders(req.headers) : req.headers
|
|
77
|
+
const headers = sourceHttp2 ? filterPseudoHeaders(req.headers) : { ...req.headers }
|
|
78
78
|
headers.host = url.host
|
|
79
79
|
const qs = getQueryString(url.search, req.url, opts)
|
|
80
80
|
let body = ''
|
package/lib/request.js
CHANGED
|
@@ -5,7 +5,7 @@ const querystring = require('querystring')
|
|
|
5
5
|
const eos = require('end-of-stream')
|
|
6
6
|
const pump = require('pump')
|
|
7
7
|
const undici = require('undici')
|
|
8
|
-
const {
|
|
8
|
+
const { stripHttp1ConnectionHeaders } = require('./utils')
|
|
9
9
|
const http2 = require('http2')
|
|
10
10
|
|
|
11
11
|
const {
|
|
@@ -158,7 +158,7 @@ function buildRequest (opts) {
|
|
|
158
158
|
// using delete, otherwise it will render as an empty string
|
|
159
159
|
delete res.headers['transfer-encoding']
|
|
160
160
|
|
|
161
|
-
done(null, { statusCode: res.statusCode, headers:
|
|
161
|
+
done(null, { statusCode: res.statusCode, headers: res.headers, stream: res.body })
|
|
162
162
|
})
|
|
163
163
|
}
|
|
164
164
|
|
package/lib/utils.js
CHANGED
|
@@ -12,31 +12,6 @@ function filterPseudoHeaders (headers) {
|
|
|
12
12
|
return dest
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
// http requires the header to be encoded with latin1
|
|
16
|
-
// undici will convert the latin1 buffer to utf8
|
|
17
|
-
// https://github.com/nodejs/undici/blob/2b260c997ad4efe4ed2064b264b4b546a59e7a67/lib/core/util.js#L216-L229
|
|
18
|
-
// after chaining, the header will be serialised using wrong encoding
|
|
19
|
-
// Buffer.from('', 'latin1').toString('utf8') applied
|
|
20
|
-
//
|
|
21
|
-
// in order to persist the encoding, always encode it
|
|
22
|
-
// back to latin1
|
|
23
|
-
function patchUndiciHeaders (headers) {
|
|
24
|
-
const headersKeys = Object.keys(headers)
|
|
25
|
-
const dist = {}
|
|
26
|
-
|
|
27
|
-
let header
|
|
28
|
-
let i
|
|
29
|
-
|
|
30
|
-
for (i = 0; i < headersKeys.length; i++) {
|
|
31
|
-
header = headersKeys[i]
|
|
32
|
-
if (header.charCodeAt(0) !== 58) { // fast path for indexOf(':') === 0
|
|
33
|
-
dist[header] = Buffer.from(headers[header]).toString('latin1')
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return dist
|
|
38
|
-
}
|
|
39
|
-
|
|
40
15
|
function copyHeaders (headers, reply) {
|
|
41
16
|
const headersKeys = Object.keys(headers)
|
|
42
17
|
|
|
@@ -99,7 +74,6 @@ function buildURL (source, reqBase) {
|
|
|
99
74
|
}
|
|
100
75
|
|
|
101
76
|
module.exports = {
|
|
102
|
-
patchUndiciHeaders,
|
|
103
77
|
copyHeaders,
|
|
104
78
|
stripHttp1ConnectionHeaders,
|
|
105
79
|
filterPseudoHeaders,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/reply-from",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.3",
|
|
4
4
|
"description": "forward your HTTP request to another server, for fastify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"fastify-plugin": "^4.0.0",
|
|
56
56
|
"pump": "^3.0.0",
|
|
57
57
|
"tiny-lru": "^10.0.0",
|
|
58
|
-
"undici": "^5.
|
|
58
|
+
"undici": "^5.19.1"
|
|
59
59
|
},
|
|
60
60
|
"pre-commit": [
|
|
61
61
|
"lint",
|
package/test/host-header.js
CHANGED
|
@@ -18,7 +18,13 @@ test('hostname', async (t) => {
|
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
instance.get('*', (request, reply) => {
|
|
21
|
-
reply.from(
|
|
21
|
+
reply.from(null, {
|
|
22
|
+
rewriteRequestHeaders: (originalReq, headers) => {
|
|
23
|
+
t.equal(headers.host, 'httpbin.org')
|
|
24
|
+
t.equal(originalReq.headers.host, `localhost:${instance.server.address().port}`)
|
|
25
|
+
return headers
|
|
26
|
+
}
|
|
27
|
+
})
|
|
22
28
|
})
|
|
23
29
|
|
|
24
30
|
instance.register(From, {
|