• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6if (common.isWindows)
7  common.skip('no mkfifo on Windows');
8const child_process = require('child_process');
9const path = require('path');
10const fs = require('fs');
11const http2 = require('http2');
12const assert = require('assert');
13
14const tmpdir = require('../common/tmpdir');
15tmpdir.refresh();
16
17const pipeName = path.join(tmpdir.path, 'pipe');
18
19const mkfifo = child_process.spawnSync('mkfifo', [ pipeName ]);
20if (mkfifo.error && mkfifo.error.code === 'ENOENT') {
21  common.skip('missing mkfifo');
22}
23
24const server = http2.createServer();
25server.on('stream', (stream) => {
26  stream.respondWithFile(pipeName, {
27    'content-type': 'text/plain'
28  }, {
29    offset: 10,
30    onError(err) {
31      common.expectsError({
32        code: 'ERR_HTTP2_SEND_FILE_NOSEEK',
33        name: 'Error',
34        message: 'Offset or length can only be specified for regular files'
35      })(err);
36
37      stream.respond({ ':status': 404 });
38      stream.end();
39    },
40    statCheck: common.mustNotCall()
41  });
42});
43server.listen(0, () => {
44
45  const client = http2.connect(`http://localhost:${server.address().port}`);
46  const req = client.request();
47
48  req.on('response', common.mustCall((headers) => {
49    assert.strictEqual(headers[':status'], 404);
50  }));
51  req.on('data', common.mustNotCall());
52  req.on('end', common.mustCall(() => {
53    client.close();
54    server.close();
55  }));
56  req.end();
57});
58
59fs.writeFile(pipeName, 'Hello, world!\n', common.mustCall((err) => {
60  // It's possible for the reading end of the pipe to get the expected error
61  // and break everything down before we're finished, so allow `EPIPE` but
62  // no other errors.
63  if (err?.code !== 'EPIPE') {
64    assert.ifError(err);
65  }
66}));
67