Skip to content

Commit

Permalink
Revert "fix: undici headers (#289)"
Browse files Browse the repository at this point in the history
Partial revert of 09cb8e7
Keep the test-case and upgrade undici
  • Loading branch information
climba03003 committed Feb 13, 2023
1 parent afa1f6f commit 65ea844
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const querystring = require('querystring')
const eos = require('end-of-stream')
const pump = require('pump')
const undici = require('undici')
const { patchUndiciHeaders, stripHttp1ConnectionHeaders } = require('./utils')
const { stripHttp1ConnectionHeaders } = require('./utils')
const http2 = require('http2')

const {
Expand Down Expand Up @@ -158,7 +158,7 @@ function buildRequest (opts) {
// using delete, otherwise it will render as an empty string
delete res.headers['transfer-encoding']

done(null, { statusCode: res.statusCode, headers: patchUndiciHeaders(res.headers), stream: res.body })
done(null, { statusCode: res.statusCode, headers: res.headers, stream: res.body })
})
}

Expand Down
26 changes: 0 additions & 26 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@ function filterPseudoHeaders (headers) {
return dest
}

// http requires the header to be encoded with latin1
// undici will convert the latin1 buffer to utf8
// https://github.com/nodejs/undici/blob/2b260c997ad4efe4ed2064b264b4b546a59e7a67/lib/core/util.js#L216-L229
// after chaining, the header will be serialised using wrong encoding
// Buffer.from('', 'latin1').toString('utf8') applied
//
// in order to persist the encoding, always encode it
// back to latin1
function patchUndiciHeaders (headers) {
const headersKeys = Object.keys(headers)
const dist = {}

let header
let i

for (i = 0; i < headersKeys.length; i++) {
header = headersKeys[i]
if (header.charCodeAt(0) !== 58) { // fast path for indexOf(':') === 0
dist[header] = Buffer.from(headers[header]).toString('latin1')
}
}

return dist
}

function copyHeaders (headers, reply) {
const headersKeys = Object.keys(headers)

Expand Down Expand Up @@ -99,7 +74,6 @@ function buildURL (source, reqBase) {
}

module.exports = {
patchUndiciHeaders,
copyHeaders,
stripHttp1ConnectionHeaders,
filterPseudoHeaders,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"fastify-plugin": "^4.0.0",
"pump": "^3.0.0",
"tiny-lru": "^10.0.0",
"undici": "^5.5.1"
"undici": "^5.19.1"
},
"pre-commit": [
"lint",
Expand Down

0 comments on commit 65ea844

Please sign in to comment.