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 h2 = require('http2'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// Http2ServerResponse should have a statusCode property 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst server = h2.createServer(); 121cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(function() { 131cb0ef41Sopenharmony_ci const port = server.address().port; 141cb0ef41Sopenharmony_ci server.once('request', common.mustCall(function(request, response) { 151cb0ef41Sopenharmony_ci const expectedDefaultStatusCode = 200; 161cb0ef41Sopenharmony_ci const realStatusCodes = { 171cb0ef41Sopenharmony_ci continue: 100, 181cb0ef41Sopenharmony_ci ok: 200, 191cb0ef41Sopenharmony_ci multipleChoices: 300, 201cb0ef41Sopenharmony_ci badRequest: 400, 211cb0ef41Sopenharmony_ci internalServerError: 500 221cb0ef41Sopenharmony_ci }; 231cb0ef41Sopenharmony_ci const fakeStatusCodes = { 241cb0ef41Sopenharmony_ci tooLow: 99, 251cb0ef41Sopenharmony_ci tooHigh: 600 261cb0ef41Sopenharmony_ci }; 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci assert.strictEqual(response.statusCode, expectedDefaultStatusCode); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci // Setting the response.statusCode should not throw. 311cb0ef41Sopenharmony_ci response.statusCode = realStatusCodes.ok; 321cb0ef41Sopenharmony_ci response.statusCode = realStatusCodes.multipleChoices; 331cb0ef41Sopenharmony_ci response.statusCode = realStatusCodes.badRequest; 341cb0ef41Sopenharmony_ci response.statusCode = realStatusCodes.internalServerError; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci assert.throws(() => { 371cb0ef41Sopenharmony_ci response.statusCode = realStatusCodes.continue; 381cb0ef41Sopenharmony_ci }, { 391cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_INFO_STATUS_NOT_ALLOWED', 401cb0ef41Sopenharmony_ci name: 'RangeError' 411cb0ef41Sopenharmony_ci }); 421cb0ef41Sopenharmony_ci assert.throws(() => { 431cb0ef41Sopenharmony_ci response.statusCode = fakeStatusCodes.tooLow; 441cb0ef41Sopenharmony_ci }, { 451cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_STATUS_INVALID', 461cb0ef41Sopenharmony_ci name: 'RangeError' 471cb0ef41Sopenharmony_ci }); 481cb0ef41Sopenharmony_ci assert.throws(() => { 491cb0ef41Sopenharmony_ci response.statusCode = fakeStatusCodes.tooHigh; 501cb0ef41Sopenharmony_ci }, { 511cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_STATUS_INVALID', 521cb0ef41Sopenharmony_ci name: 'RangeError' 531cb0ef41Sopenharmony_ci }); 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci response.on('finish', common.mustCall(function() { 561cb0ef41Sopenharmony_ci server.close(); 571cb0ef41Sopenharmony_ci })); 581cb0ef41Sopenharmony_ci response.end(); 591cb0ef41Sopenharmony_ci })); 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci const url = `http://localhost:${port}`; 621cb0ef41Sopenharmony_ci const client = h2.connect(url, common.mustCall(function() { 631cb0ef41Sopenharmony_ci const headers = { 641cb0ef41Sopenharmony_ci ':path': '/', 651cb0ef41Sopenharmony_ci ':method': 'GET', 661cb0ef41Sopenharmony_ci ':scheme': 'http', 671cb0ef41Sopenharmony_ci ':authority': `localhost:${port}` 681cb0ef41Sopenharmony_ci }; 691cb0ef41Sopenharmony_ci const request = client.request(headers); 701cb0ef41Sopenharmony_ci request.on('end', common.mustCall(function() { 711cb0ef41Sopenharmony_ci client.close(); 721cb0ef41Sopenharmony_ci })); 731cb0ef41Sopenharmony_ci request.end(); 741cb0ef41Sopenharmony_ci request.resume(); 751cb0ef41Sopenharmony_ci })); 761cb0ef41Sopenharmony_ci})); 77