11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst http2 = require('http2'); 71cb0ef41Sopenharmony_ciconst makeDuplexPair = require('../common/duplexpair'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci{ 101cb0ef41Sopenharmony_ci const testData = '<h1>Hello World</h1>'; 111cb0ef41Sopenharmony_ci const server = http2.createServer(); 121cb0ef41Sopenharmony_ci server.on('stream', common.mustCall((stream, headers) => { 131cb0ef41Sopenharmony_ci stream.respond({ 141cb0ef41Sopenharmony_ci 'content-type': 'text/html', 151cb0ef41Sopenharmony_ci ':status': 200 161cb0ef41Sopenharmony_ci }); 171cb0ef41Sopenharmony_ci stream.end(testData); 181cb0ef41Sopenharmony_ci })); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci const { clientSide, serverSide } = makeDuplexPair(); 211cb0ef41Sopenharmony_ci server.emit('connection', serverSide); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci const client = http2.connect('http://localhost:80', { 241cb0ef41Sopenharmony_ci createConnection: common.mustCall(() => clientSide) 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci const req = client.request({ ':path': '/' }); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci req.on('response', common.mustCall((headers) => { 301cb0ef41Sopenharmony_ci assert.strictEqual(headers[':status'], 200); 311cb0ef41Sopenharmony_ci })); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci req.setEncoding('utf8'); 341cb0ef41Sopenharmony_ci // Note: This is checking that this small amount of data is passed through in 351cb0ef41Sopenharmony_ci // a single chunk, which is unusual for our test suite but seems like a 361cb0ef41Sopenharmony_ci // reasonable assumption here. 371cb0ef41Sopenharmony_ci req.on('data', common.mustCall((data) => { 381cb0ef41Sopenharmony_ci assert.strictEqual(data, testData); 391cb0ef41Sopenharmony_ci })); 401cb0ef41Sopenharmony_ci req.on('end', common.mustCall(() => { 411cb0ef41Sopenharmony_ci clientSide.destroy(); 421cb0ef41Sopenharmony_ci clientSide.end(); 431cb0ef41Sopenharmony_ci })); 441cb0ef41Sopenharmony_ci req.end(); 451cb0ef41Sopenharmony_ci} 46