mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

This change makes it possible for userland http-related modules to pave over edge cases that require referencing the original request when handling a response--making a "Lodash for HTTP" library possible. More information and research in https://github.com/nodejs/node/issues/28673 Fixes: https://github.com/nodejs/node/issues/28673 PR-URL: https://github.com/nodejs/node/pull/36505 Reviewed-By: Robert Nagy <ronagy@icloud.com>
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const h2 = require('http2');
|
|
|
|
// Http2ServerResponse should expose convenience properties
|
|
|
|
const server = h2.createServer();
|
|
server.listen(0, common.mustCall(function() {
|
|
const port = server.address().port;
|
|
server.once('request', common.mustCall(function(request, response) {
|
|
assert.strictEqual(response.req, request);
|
|
|
|
response.on('finish', common.mustCall(function() {
|
|
process.nextTick(() => {
|
|
server.close();
|
|
});
|
|
}));
|
|
response.end();
|
|
}));
|
|
|
|
const url = `http://localhost:${port}`;
|
|
const client = h2.connect(url, common.mustCall(function() {
|
|
const headers = {
|
|
':path': '/foobar',
|
|
':method': 'GET',
|
|
':scheme': 'http',
|
|
':authority': `localhost:${port}`
|
|
};
|
|
const request = client.request(headers);
|
|
request.on('end', common.mustCall(function() {
|
|
client.close();
|
|
}));
|
|
request.end();
|
|
request.resume();
|
|
}));
|
|
}));
|