-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: fix first body chunk fast case for UTF-16
`http.OutgoingMessage` tried to send the first chunk together with the headers by concatenating them together as a string, but the list of encodings for which that works was incorrect. Change it from a blacklist to a whitelist. Fixes: #11788 PR-URL: #12747 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
test/parallel/test-http-outgoing-first-chunk-singlebyte-encoding.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/11788. | ||
|
||
const assert = require('assert'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
for (const enc of ['utf8', 'utf16le', 'latin1', 'UTF-8']) { | ||
const server = http.createServer(common.mustCall((req, res) => { | ||
res.setHeader('content-type', `text/plain; charset=${enc}`); | ||
res.write('helloworld', enc); | ||
res.end(); | ||
})).listen(0); | ||
|
||
server.on('listening', common.mustCall(() => { | ||
const buffers = []; | ||
const socket = net.connect(server.address().port); | ||
socket.write('GET / HTTP/1.0\r\n\r\n'); | ||
socket.on('data', (data) => buffers.push(data)); | ||
socket.on('end', common.mustCall(() => { | ||
const received = Buffer.concat(buffers); | ||
const headerEnd = received.indexOf('\r\n\r\n', 'utf8'); | ||
assert.notStrictEqual(headerEnd, -1); | ||
|
||
const header = received.toString('utf8', 0, headerEnd).split(/\r\n/g); | ||
const body = received.toString(enc, headerEnd + 4); | ||
|
||
assert.strictEqual(header[0], 'HTTP/1.1 200 OK'); | ||
assert.strictEqual(header[1], `content-type: text/plain; charset=${enc}`); | ||
assert.strictEqual(body, 'helloworld'); | ||
server.close(); | ||
})); | ||
})); | ||
} |