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(); 21 22 server.on('stream', common.mustCall((stream) => { 23 // Wait for some data to come through. 24 setImmediate(() => { 25 stream.on('close', common.mustCall(() => { 26 assert.strictEqual(stream.rstCode, 0); 27 })); 28 29 stream.respond({ ':status': 400 }); 30 stream.end(); 31 }); 32 })); 33 34 server.listen(0, common.mustCall(() => { 35 const client = http2.connect(`http://localhost:${server.address().port}`); 36 37 const req = client.request({ ':method': 'POST' }); 38 req.on('response', common.mustCall((headers) => { 39 assert.strictEqual(headers[':status'], 400); 40 })); 41 42 req.resume(); 43 req.on('end', common.mustCall(() => { 44 server.close(); 45 client.close(); 46 })); 47 48 const str = fs.createReadStream(loc); 49 str.pipe(req); 50 })); 51})); 52