Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 20 fixes #4473

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .labrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const Somever = require('@hapi/somever');

module.exports = {
'coverage-predicates': {
allowsStoppedReq: Somever.match(process.version, '<=18'),
}
};
6 changes: 6 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ exports = module.exports = internals.Core = class {

return (req, res) => {

// $lab:coverage:off$ $not:allowsStoppedReq$
if (this.phase === 'stopping') {
return req.destroy();
}
// $lab:coverage:on$ $not:allowsStoppedReq$

// Create request

const request = Request.generate(this.root, req, res, options);
Expand Down
4 changes: 1 addition & 3 deletions lib/transmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ internals.end = function (env, event, err) {
env.team = null;

if (request.raw.res.writableEnded) {
if (!event) {
request.info.responded = Date.now();
}
request.info.responded = Date.now();
Nargonath marked this conversation as resolved.
Show resolved Hide resolved

team.attend();
return;
Expand Down
4 changes: 3 additions & 1 deletion test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,13 @@ describe('Core', () => {
const { res, payload } = await first;
const stop = server.stop();

await expect(second).to.reject();
const err = await expect(second).to.reject(Error);
await stop;
await Hoek.wait(10);

expect(res.headers.connection).to.equal('keep-alive');
expect(payload.toString()).to.equal('ok');
expect(err.code).to.equal('ECONNRESET');
expect(server._core.started).to.equal(false);
});

Expand Down
30 changes: 26 additions & 4 deletions test/payload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

const Events = require('events');
const Fs = require('fs');
const Http = require('http');
const Net = require('net');
const Path = require('path');
const Zlib = require('zlib');

Expand Down Expand Up @@ -279,10 +281,30 @@ describe('Payload', () => {

await server.start();

const uri = 'http://localhost:' + server.info.port;
const { res, payload } = await Wreck.post(uri, { payload: { hello: true }, headers: { expect: '100-continue' } });
expect(res.statusCode).to.equal(200);
expect(payload.toString()).to.equal('{"hello":true}');
const client = Net.connect(server.info.port);

await Events.once(client, 'connect');

client.write('POST / HTTP/1.1\r\nexpect: 100-continue\r\nhost: host\r\naccept-encoding: gzip\r\n' +
'content-type: application/json\r\ncontent-length: 14\r\nConnection: close\r\n\r\n');

const lines = [];
client.setEncoding('ascii');
for await (const chunk of client) {

if (chunk.startsWith('HTTP/1.1 100 Continue')) {
client.write('{"hello":true}');
}
else {
lines.push(...chunk.split('\r\n'));
}
}

const res = lines.shift();
const payload = lines.pop();

expect(res).to.equal('HTTP/1.1 200 OK');
expect(payload).to.equal('{"hello":true}');

await server.stop();
});
Expand Down
10 changes: 5 additions & 5 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ describe('Request', () => {

const client = Net.connect(server.info.port, () => {

client.write('GET / HTTP/1.1\r\n\r\n');
client.write('GET / HTTP/1.1\r\n\r\n');
client.write('GET / HTTP/1.1\r\nHost: host\r\n\r\n');
client.write('GET / HTTP/1.1\r\nHost: host\r\n\r\n');
});

client.on('data', () => {
Expand Down Expand Up @@ -662,9 +662,9 @@ describe('Request', () => {

const client = Net.connect(server.info.port, () => {

client.write('GET /test HTTP/1.1\r\n\r\n');
client.write('GET /test HTTP/1.1\r\n\r\n');
client.write('GET /test HTTP/1.1\r\n\r\n');
client.write('GET /test HTTP/1.1\r\nHost: host\r\n\r\n');
client.write('GET /test HTTP/1.1\r\nHost: host\r\n\r\n');
client.write('GET /test HTTP/1.1\r\nHost: host\r\n\r\n');
});

await team.work;
Expand Down
2 changes: 1 addition & 1 deletion test/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('Route', () => {
expect(res.statusCode).to.equal(200);
expect(logged).to.be.an.object();
expect(logged.error).to.be.an.error('Invalid request payload JSON format');
expect(logged.error.data).to.be.an.error(SyntaxError, /^Unexpected token a/);
expect(logged.error.data).to.be.an.error(SyntaxError, /at position 1/);
});

it('returns payload parsing errors', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/transmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ describe('transmission', () => {
const log = server.events.once('response');
const client = Net.connect(server.info.port, () => {

client.write('GET / HTTP/1.1\r\naccept-encoding: gzip\r\n\r\n');
client.write('GET / HTTP/1.1\r\nHost: host\r\naccept-encoding: gzip\r\n\r\n');
Nargonath marked this conversation as resolved.
Show resolved Hide resolved
});

const [request] = await log;
Expand Down
Loading