Skip to content

Commit

Permalink
perf: latin1 (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Apr 16, 2023
1 parent 3b3ee20 commit 472c40e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1451,17 +1451,17 @@ function write (client, request) {
/* istanbul ignore else: assertion */
if (!body) {
if (contentLength === 0) {
socket.write(`${header}content-length: 0\r\n\r\n`, 'ascii')
socket.write(`${header}content-length: 0\r\n\r\n`, 'latin1')
} else {
assert(contentLength === null, 'no body must not have content length')
socket.write(`${header}\r\n`, 'ascii')
socket.write(`${header}\r\n`, 'latin1')
}
request.onRequestSent()
} else if (util.isBuffer(body)) {
assert(contentLength === body.byteLength, 'buffer body must have content length')

socket.cork()
socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'ascii')
socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
socket.write(body)
socket.uncork()
request.onBodySent(body)
Expand Down Expand Up @@ -1576,7 +1576,7 @@ async function writeBlob ({ body, client, request, socket, contentLength, header
const buffer = Buffer.from(await body.arrayBuffer())

socket.cork()
socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'ascii')
socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
socket.write(buffer)
socket.uncork()

Expand Down Expand Up @@ -1688,14 +1688,14 @@ class AsyncWriter {
}

if (contentLength === null) {
socket.write(`${header}transfer-encoding: chunked\r\n`, 'ascii')
socket.write(`${header}transfer-encoding: chunked\r\n`, 'latin1')
} else {
socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'ascii')
socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
}
}

if (contentLength === null) {
socket.write(`\r\n${len.toString(16)}\r\n`, 'ascii')
socket.write(`\r\n${len.toString(16)}\r\n`, 'latin1')
}

this.bytesWritten += len
Expand Down Expand Up @@ -1739,12 +1739,12 @@ class AsyncWriter {
// no Transfer-Encoding is sent and the request method defines a meaning
// for an enclosed payload body.

socket.write(`${header}content-length: 0\r\n\r\n`, 'ascii')
socket.write(`${header}content-length: 0\r\n\r\n`, 'latin1')
} else {
socket.write(`${header}\r\n`, 'ascii')
socket.write(`${header}\r\n`, 'latin1')
}
} else if (contentLength === null) {
socket.write('\r\n0\r\n\r\n', 'ascii')
socket.write('\r\n0\r\n\r\n', 'latin1')
}

if (contentLength !== null && bytesWritten !== contentLength) {
Expand Down

0 comments on commit 472c40e

Please sign in to comment.