11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst inspect = require('util').inspect; 51cb0ef41Sopenharmony_ciconst { _checkIsHttpToken, _checkInvalidHeaderChar } = require('_http_common'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// Good header field names 81cb0ef41Sopenharmony_ci[ 91cb0ef41Sopenharmony_ci 'TCN', 101cb0ef41Sopenharmony_ci 'ETag', 111cb0ef41Sopenharmony_ci 'date', 121cb0ef41Sopenharmony_ci 'alt-svc', 131cb0ef41Sopenharmony_ci 'Content-Type', 141cb0ef41Sopenharmony_ci '0', 151cb0ef41Sopenharmony_ci 'Set-Cookie2', 161cb0ef41Sopenharmony_ci 'Set_Cookie', 171cb0ef41Sopenharmony_ci 'foo`bar^', 181cb0ef41Sopenharmony_ci 'foo|bar', 191cb0ef41Sopenharmony_ci '~foobar', 201cb0ef41Sopenharmony_ci 'FooBar!', 211cb0ef41Sopenharmony_ci '#Foo', 221cb0ef41Sopenharmony_ci '$et-Cookie', 231cb0ef41Sopenharmony_ci '%%Test%%', 241cb0ef41Sopenharmony_ci 'Test&123', 251cb0ef41Sopenharmony_ci 'It\'s_fun', 261cb0ef41Sopenharmony_ci '2*3', 271cb0ef41Sopenharmony_ci '4+2', 281cb0ef41Sopenharmony_ci '3.14159265359', 291cb0ef41Sopenharmony_ci].forEach(function(str) { 301cb0ef41Sopenharmony_ci assert.strictEqual( 311cb0ef41Sopenharmony_ci _checkIsHttpToken(str), true, 321cb0ef41Sopenharmony_ci `_checkIsHttpToken(${inspect(str)}) unexpectedly failed`); 331cb0ef41Sopenharmony_ci}); 341cb0ef41Sopenharmony_ci// Bad header field names 351cb0ef41Sopenharmony_ci[ 361cb0ef41Sopenharmony_ci ':', 371cb0ef41Sopenharmony_ci '@@', 381cb0ef41Sopenharmony_ci '中文呢', // unicode 391cb0ef41Sopenharmony_ci '((((())))', 401cb0ef41Sopenharmony_ci ':alternate-protocol', 411cb0ef41Sopenharmony_ci 'alternate-protocol:', 421cb0ef41Sopenharmony_ci 'foo\nbar', 431cb0ef41Sopenharmony_ci 'foo\rbar', 441cb0ef41Sopenharmony_ci 'foo\r\nbar', 451cb0ef41Sopenharmony_ci 'foo\x00bar', 461cb0ef41Sopenharmony_ci '\x7FMe!', 471cb0ef41Sopenharmony_ci '{Start', 481cb0ef41Sopenharmony_ci '(Start', 491cb0ef41Sopenharmony_ci '[Start', 501cb0ef41Sopenharmony_ci 'End}', 511cb0ef41Sopenharmony_ci 'End)', 521cb0ef41Sopenharmony_ci 'End]', 531cb0ef41Sopenharmony_ci '"Quote"', 541cb0ef41Sopenharmony_ci 'This,That', 551cb0ef41Sopenharmony_ci].forEach(function(str) { 561cb0ef41Sopenharmony_ci assert.strictEqual( 571cb0ef41Sopenharmony_ci _checkIsHttpToken(str), false, 581cb0ef41Sopenharmony_ci `_checkIsHttpToken(${inspect(str)}) unexpectedly succeeded`); 591cb0ef41Sopenharmony_ci}); 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci// Good header field values 631cb0ef41Sopenharmony_ci[ 641cb0ef41Sopenharmony_ci 'foo bar', 651cb0ef41Sopenharmony_ci 'foo\tbar', 661cb0ef41Sopenharmony_ci '0123456789ABCdef', 671cb0ef41Sopenharmony_ci '!@#$%^&*()-_=+\\;\':"[]{}<>,./?|~`', 681cb0ef41Sopenharmony_ci].forEach(function(str) { 691cb0ef41Sopenharmony_ci assert.strictEqual( 701cb0ef41Sopenharmony_ci _checkInvalidHeaderChar(str), false, 711cb0ef41Sopenharmony_ci `_checkInvalidHeaderChar(${inspect(str)}) unexpectedly failed`); 721cb0ef41Sopenharmony_ci}); 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci// Bad header field values 751cb0ef41Sopenharmony_ci[ 761cb0ef41Sopenharmony_ci 'foo\rbar', 771cb0ef41Sopenharmony_ci 'foo\nbar', 781cb0ef41Sopenharmony_ci 'foo\r\nbar', 791cb0ef41Sopenharmony_ci '中文呢', // unicode 801cb0ef41Sopenharmony_ci '\x7FMe!', 811cb0ef41Sopenharmony_ci 'Testing 123\x00', 821cb0ef41Sopenharmony_ci 'foo\vbar', 831cb0ef41Sopenharmony_ci 'Ding!\x07', 841cb0ef41Sopenharmony_ci].forEach(function(str) { 851cb0ef41Sopenharmony_ci assert.strictEqual( 861cb0ef41Sopenharmony_ci _checkInvalidHeaderChar(str), true, 871cb0ef41Sopenharmony_ci `_checkInvalidHeaderChar(${inspect(str)}) unexpectedly succeeded`); 881cb0ef41Sopenharmony_ci}); 89