File tree Expand file tree Collapse file tree 1 file changed +97
-0
lines changed Expand file tree Collapse file tree 1 file changed +97
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const inspect = require ( 'util' ) . inspect ;
5+ const checkIsHttpToken = require ( '_http_common' ) . _checkIsHttpToken ;
6+ const checkInvalidHeaderChar = require ( '_http_common' ) . _checkInvalidHeaderChar ;
7+
8+ // Good header field names
9+ [
10+ 'TCN' ,
11+ 'ETag' ,
12+ 'date' ,
13+ 'alt-svc' ,
14+ 'Content-Type' ,
15+ '0' ,
16+ 'Set-Cookie2' ,
17+ 'Set_Cookie' ,
18+ 'foo`bar^' ,
19+ 'foo|bar' ,
20+ '~foobar' ,
21+ 'FooBar!' ,
22+ '#Foo' ,
23+ '$et-Cookie' ,
24+ '%%Test%%' ,
25+ 'Test&123' ,
26+ 'It\'s_fun' ,
27+ '2*3' ,
28+ '4+2' ,
29+ '3.14159265359'
30+ ] . forEach ( function ( str ) {
31+ assert . strictEqual ( checkIsHttpToken ( str ) ,
32+ true ,
33+ 'checkIsHttpToken(' +
34+ inspect ( str ) +
35+ ') unexpectedly failed' ) ;
36+ } ) ;
37+ // Bad header field names
38+ [
39+ ':' ,
40+ '@@' ,
41+ '中文呢' , // unicode
42+ '((((())))' ,
43+ ':alternate-protocol' ,
44+ 'alternate-protocol:' ,
45+ 'foo\nbar' ,
46+ 'foo\rbar' ,
47+ 'foo\r\nbar' ,
48+ 'foo\x00bar' ,
49+ '\x7FMe!' ,
50+ '{Start' ,
51+ '(Start' ,
52+ '[Start' ,
53+ 'End}' ,
54+ 'End)' ,
55+ 'End]' ,
56+ '"Quote"' ,
57+ 'This,That'
58+ ] . forEach ( function ( str ) {
59+ assert . strictEqual ( checkIsHttpToken ( str ) ,
60+ false ,
61+ 'checkIsHttpToken(' +
62+ inspect ( str ) +
63+ ') unexpectedly succeeded' ) ;
64+ } ) ;
65+
66+
67+ // Good header field values
68+ [
69+ 'foo bar' ,
70+ 'foo\tbar' ,
71+ '0123456789ABCdef' ,
72+ '!@#$%^&*()-_=+\\;\':"[]{}<>,./?|~`'
73+ ] . forEach ( function ( str ) {
74+ assert . strictEqual ( checkInvalidHeaderChar ( str ) ,
75+ false ,
76+ 'checkInvalidHeaderChar(' +
77+ inspect ( str ) +
78+ ') unexpectedly failed' ) ;
79+ } ) ;
80+
81+ // Bad header field values
82+ [
83+ 'foo\rbar' ,
84+ 'foo\nbar' ,
85+ 'foo\r\nbar' ,
86+ '中文呢' , // unicode
87+ '\x7FMe!' ,
88+ 'Testing 123\x00' ,
89+ 'foo\vbar' ,
90+ 'Ding!\x07'
91+ ] . forEach ( function ( str ) {
92+ assert . strictEqual ( checkInvalidHeaderChar ( str ) ,
93+ true ,
94+ 'checkInvalidHeaderChar(' +
95+ inspect ( str ) +
96+ ') unexpectedly succeeded' ) ;
97+ } ) ;
You can’t perform that action at this time.
0 commit comments