11cb0ef41Sopenharmony_ci// Spec documentation http://httpwg.github.io/specs/rfc7231.html#header.expect 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst http = require('http'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst tests = [417, 417]; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cilet testsComplete = 0; 101cb0ef41Sopenharmony_cilet testIdx = 0; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst s = http.createServer((req, res) => { 131cb0ef41Sopenharmony_ci throw new Error('this should never be executed'); 141cb0ef41Sopenharmony_ci}); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cis.listen(0, nextTest); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cifunction nextTest() { 191cb0ef41Sopenharmony_ci const options = { 201cb0ef41Sopenharmony_ci port: s.address().port, 211cb0ef41Sopenharmony_ci headers: { 'Expect': 'meoww' } 221cb0ef41Sopenharmony_ci }; 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci if (testIdx === tests.length) { 251cb0ef41Sopenharmony_ci return s.close(); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci const test = tests[testIdx]; 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci if (testIdx > 0) { 311cb0ef41Sopenharmony_ci s.on('checkExpectation', common.mustCall((req, res) => { 321cb0ef41Sopenharmony_ci res.statusCode = 417; 331cb0ef41Sopenharmony_ci res.end(); 341cb0ef41Sopenharmony_ci })); 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci http.get(options, (response) => { 381cb0ef41Sopenharmony_ci console.log(`client: expected status: ${test}`); 391cb0ef41Sopenharmony_ci console.log(`client: statusCode: ${response.statusCode}`); 401cb0ef41Sopenharmony_ci assert.strictEqual(response.statusCode, test); 411cb0ef41Sopenharmony_ci assert.strictEqual(response.statusMessage, 'Expectation Failed'); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci response.on('end', () => { 441cb0ef41Sopenharmony_ci testsComplete++; 451cb0ef41Sopenharmony_ci testIdx++; 461cb0ef41Sopenharmony_ci nextTest(); 471cb0ef41Sopenharmony_ci }); 481cb0ef41Sopenharmony_ci response.resume(); 491cb0ef41Sopenharmony_ci }); 501cb0ef41Sopenharmony_ci} 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ciprocess.on('exit', () => { 541cb0ef41Sopenharmony_ci assert.strictEqual(testsComplete, 2); 551cb0ef41Sopenharmony_ci}); 56