-
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.
http2: remove regular-file-only restriction
Requiring `respondWithFile()` to only work with regular files is an artificial restriction on Node’s side and has become unnecessary. Offsets or lengths cannot be specified for those files, but that is an inherent property of other file types. PR-URL: #18936 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
7 changed files
with
164 additions
and
14 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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
test/parallel/test-http2-respond-file-error-pipe-offset.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,61 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
if (common.isWindows) | ||
common.skip('no mkfifo on Windows'); | ||
const child_process = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const http2 = require('http2'); | ||
const assert = require('assert'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const pipeName = path.join(tmpdir.path, 'pipe'); | ||
|
||
const mkfifo = child_process.spawnSync('mkfifo', [ pipeName ]); | ||
if (mkfifo.error && mkfifo.error.code === 'ENOENT') { | ||
common.skip('missing mkfifo'); | ||
} | ||
|
||
process.on('exit', () => fs.unlinkSync(pipeName)); | ||
|
||
const server = http2.createServer(); | ||
server.on('stream', (stream) => { | ||
stream.respondWithFile(pipeName, { | ||
'content-type': 'text/plain' | ||
}, { | ||
offset: 10, | ||
onError(err) { | ||
common.expectsError({ | ||
code: 'ERR_HTTP2_SEND_FILE_NOSEEK', | ||
type: Error, | ||
message: 'Offset or length can only be specified for regular files' | ||
})(err); | ||
|
||
stream.respond({ ':status': 404 }); | ||
stream.end(); | ||
}, | ||
statCheck: common.mustNotCall() | ||
}); | ||
}); | ||
server.listen(0, () => { | ||
|
||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
const req = client.request(); | ||
|
||
req.on('response', common.mustCall((headers) => { | ||
assert.strictEqual(headers[':status'], 404); | ||
})); | ||
req.on('data', common.mustNotCall()); | ||
req.on('end', common.mustCall(() => { | ||
client.close(); | ||
server.close(); | ||
})); | ||
req.end(); | ||
}); | ||
|
||
fs.writeFile(pipeName, 'Hello, world!\n', common.mustCall()); |
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,58 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
if (common.isWindows) | ||
common.skip('no mkfifo on Windows'); | ||
const child_process = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const http2 = require('http2'); | ||
const assert = require('assert'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const pipeName = path.join(tmpdir.path, 'pipe'); | ||
|
||
const mkfifo = child_process.spawnSync('mkfifo', [ pipeName ]); | ||
if (mkfifo.error && mkfifo.error.code === 'ENOENT') { | ||
common.skip('missing mkfifo'); | ||
} | ||
|
||
process.on('exit', () => fs.unlinkSync(pipeName)); | ||
|
||
const server = http2.createServer(); | ||
server.on('stream', (stream) => { | ||
stream.respondWithFile(pipeName, { | ||
'content-type': 'text/plain' | ||
}, { | ||
onError: common.mustNotCall(), | ||
statCheck: common.mustCall() | ||
}); | ||
}); | ||
|
||
server.listen(0, () => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
const req = client.request(); | ||
|
||
req.on('response', common.mustCall((headers) => { | ||
assert.strictEqual(headers[':status'], 200); | ||
})); | ||
let body = ''; | ||
req.setEncoding('utf8'); | ||
req.on('data', (chunk) => body += chunk); | ||
req.on('end', common.mustCall(() => { | ||
assert.strictEqual(body, 'Hello, world!\n'); | ||
client.close(); | ||
server.close(); | ||
})); | ||
req.end(); | ||
}); | ||
|
||
fs.open(pipeName, 'w', common.mustCall((err, fd) => { | ||
assert.ifError(err); | ||
fs.writeSync(fd, 'Hello, world!\n'); | ||
fs.closeSync(fd); | ||
})); |