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