• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Verifies that uploading data from a client works
4
5const common = require('../common');
6if (!common.hasCrypto)
7  common.skip('missing crypto');
8const assert = require('assert');
9const http2 = require('http2');
10const fs = require('fs');
11const fixtures = require('../common/fixtures');
12
13const loc = fixtures.path('person-large.jpg');
14
15assert(fs.existsSync(loc));
16
17fs.readFile(loc, common.mustCall((err, data) => {
18  assert.ifError(err);
19
20  const server = http2.createServer(common.mustCall((req, res) => {
21    setImmediate(() => {
22      res.writeHead(400);
23      res.end();
24    });
25  }));
26  server.on('close', common.mustCall());
27
28  server.listen(0, common.mustCall(() => {
29    const client = http2.connect(`http://localhost:${server.address().port}`);
30    client.on('close', common.mustCall());
31
32    const req = client.request({ ':method': 'POST' });
33    req.on('response', common.mustCall((headers) => {
34      assert.strictEqual(headers[':status'], 400);
35    }));
36
37    req.resume();
38    req.on('end', common.mustCall(() => {
39      server.close();
40      client.close();
41    }));
42
43    const str = fs.createReadStream(loc);
44    str.pipe(req);
45  }));
46}));
47