11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst http2 = require('http2'); 81cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst server = http2.createServer(); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => { 131cb0ef41Sopenharmony_ci stream.respond(); 141cb0ef41Sopenharmony_ci stream.end(); 151cb0ef41Sopenharmony_ci})); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 181cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci const countdown = new Countdown(2, () => { 211cb0ef41Sopenharmony_ci server.close(); 221cb0ef41Sopenharmony_ci client.close(); 231cb0ef41Sopenharmony_ci }); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci // Request 1 will fail because there are two content-length header values 261cb0ef41Sopenharmony_ci assert.throws( 271cb0ef41Sopenharmony_ci () => { 281cb0ef41Sopenharmony_ci client.request({ 291cb0ef41Sopenharmony_ci ':method': 'POST', 301cb0ef41Sopenharmony_ci 'content-length': 1, 311cb0ef41Sopenharmony_ci 'Content-Length': 2 321cb0ef41Sopenharmony_ci }); 331cb0ef41Sopenharmony_ci }, { 341cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', 351cb0ef41Sopenharmony_ci name: 'TypeError', 361cb0ef41Sopenharmony_ci message: 'Header field "content-length" must only have a single value' 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci ); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci { 411cb0ef41Sopenharmony_ci // Request 2 will succeed 421cb0ef41Sopenharmony_ci const req = client.request({ 431cb0ef41Sopenharmony_ci ':method': 'POST', 441cb0ef41Sopenharmony_ci 'content-length': 1 451cb0ef41Sopenharmony_ci }); 461cb0ef41Sopenharmony_ci req.resume(); 471cb0ef41Sopenharmony_ci req.on('end', common.mustCall()); 481cb0ef41Sopenharmony_ci req.on('close', common.mustCall(() => countdown.dec())); 491cb0ef41Sopenharmony_ci req.end('a'); 501cb0ef41Sopenharmony_ci } 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci { 531cb0ef41Sopenharmony_ci // Request 3 will fail because nghttp2 does not allow the content-length 541cb0ef41Sopenharmony_ci // header to be set for non-payload bearing requests... 551cb0ef41Sopenharmony_ci const req = client.request({ 'content-length': 1 }); 561cb0ef41Sopenharmony_ci req.resume(); 571cb0ef41Sopenharmony_ci req.on('end', common.mustNotCall()); 581cb0ef41Sopenharmony_ci req.on('close', common.mustCall(() => countdown.dec())); 591cb0ef41Sopenharmony_ci req.on('error', common.expectsError({ 601cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_STREAM_ERROR', 611cb0ef41Sopenharmony_ci name: 'Error', 621cb0ef41Sopenharmony_ci message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR' 631cb0ef41Sopenharmony_ci })); 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci})); 66