@@ -16,17 +16,24 @@ describe('Headers', () => {
16
16
} ) ;
17
17
18
18
it ( 'should initialize with provided headers' , ( ) => {
19
- const initialHeaders = { 'content-type ' : 'application/json' } ;
19
+ const initialHeaders = { 'Content-Type ' : 'application/json' } ;
20
20
const headers = createHeaders ( initialHeaders ) ;
21
21
22
- expect ( headers [ 'content-type' ] ) . to . equal ( 'application/json' ) ;
22
+ expect ( headers [ 'Content-Type' ] ) . to . equal ( 'application/json' ) ;
23
+ } ) ;
24
+
25
+ it ( 'should allow to directly access headers' , ( ) => {
26
+ const headers = createHeaders ( ) ;
27
+ headers [ 'Content-Type' ] = 'application/json' ;
28
+
29
+ expect ( headers [ 'Content-Type' ] ) . to . equal ( 'application/json' ) ;
23
30
} ) ;
24
31
} ) ;
25
32
26
33
describe ( 'Headers Web API Methods' , ( ) => {
27
34
describe ( '#get()' , ( ) => {
28
35
it ( 'should get a header value' , ( ) => {
29
- const headers = createHeaders ( { 'content-type ' : 'application/json' } ) ;
36
+ const headers = createHeaders ( { 'Content-Type ' : 'application/json' } ) ;
30
37
31
38
expect ( headers . get ( 'content-type' ) ) . to . equal ( 'application/json' ) ;
32
39
expect ( headers . get ( 'Content-Type' ) ) . to . equal ( 'application/json' ) ;
@@ -35,7 +42,7 @@ describe('Headers', () => {
35
42
it ( 'should return undefined for non-existent headers' , ( ) => {
36
43
const headers = createHeaders ( ) ;
37
44
38
- expect ( headers . get ( 'content-type ' ) ) . to . be . undefined ;
45
+ expect ( headers . get ( 'cContent-Type ' ) ) . to . be . undefined ;
39
46
} ) ;
40
47
41
48
it ( 'should handle the referer/referrer special case' , ( ) => {
@@ -49,27 +56,27 @@ describe('Headers', () => {
49
56
50
57
describe ( '#getAll()' , ( ) => {
51
58
it ( 'should get all values for a header as an array' , ( ) => {
52
- const headers = createHeaders ( { 'set-cookie ' : [ 'cookie1=value1' , 'cookie2=value2' ] } ) ;
59
+ const headers = createHeaders ( { 'Set-Cookie ' : [ 'cookie1=value1' , 'cookie2=value2' ] } ) ;
53
60
54
- expect ( headers . getAll ( 'set-cookie ' ) ) . to . deep . equal ( [ 'cookie1=value1' , 'cookie2=value2' ] ) ;
61
+ expect ( headers . getAll ( 'Set-Cookie ' ) ) . to . deep . equal ( [ 'cookie1=value1' , 'cookie2=value2' ] ) ;
55
62
} ) ;
56
63
57
64
it ( 'should return a single value as an array' , ( ) => {
58
- const headers = createHeaders ( { 'content-type ' : 'application/json' } ) ;
65
+ const headers = createHeaders ( { 'Content-Type ' : 'application/json' } ) ;
59
66
60
- expect ( headers . getAll ( 'content-type ' ) ) . to . deep . equal ( [ 'application/json' ] ) ;
67
+ expect ( headers . getAll ( 'Content-Type ' ) ) . to . deep . equal ( [ 'application/json' ] ) ;
61
68
} ) ;
62
69
63
70
it ( 'should return an empty array for non-existent headers' , ( ) => {
64
71
const headers = createHeaders ( ) ;
65
72
66
- expect ( headers . getAll ( 'content-type ' ) ) . to . deep . equal ( [ ] ) ;
73
+ expect ( headers . getAll ( 'Content-Type ' ) ) . to . deep . equal ( [ ] ) ;
67
74
} ) ;
68
75
} ) ;
69
76
70
77
describe ( '#has()' , ( ) => {
71
78
it ( 'should check if a header exists' , ( ) => {
72
- const headers = createHeaders ( { 'content-type ' : 'application/json' } ) ;
79
+ const headers = createHeaders ( { 'Content-Type ' : 'application/json' } ) ;
73
80
74
81
expect ( headers . has ( 'content-type' ) ) . to . be . true ;
75
82
expect ( headers . has ( 'Content-Type' ) ) . to . be . true ;
@@ -78,60 +85,60 @@ describe('Headers', () => {
78
85
it ( 'should return false for non-existent headers' , ( ) => {
79
86
const headers = createHeaders ( ) ;
80
87
81
- expect ( headers . has ( 'content-type ' ) ) . to . be . false ;
88
+ expect ( headers . has ( 'Content-Type ' ) ) . to . be . false ;
82
89
} ) ;
83
90
} ) ;
84
91
85
92
describe ( '#set()' , ( ) => {
86
93
it ( 'should set a header value' , ( ) => {
87
94
const headers = createHeaders ( ) ;
88
95
89
- headers . set ( 'content-type ' , 'application/json' ) ;
90
- expect ( headers [ 'content-type ' ] ) . to . equal ( 'application/json' ) ;
96
+ headers . set ( 'Content-Type ' , 'application/json' ) ;
97
+ expect ( headers [ 'Content-Type ' ] ) . to . equal ( 'application/json' ) ;
91
98
} ) ;
92
99
93
100
it ( 'should overwrite existing headers' , ( ) => {
94
- const headers = createHeaders ( { 'content-type ' : 'text/html' } ) ;
101
+ const headers = createHeaders ( { 'Content-Type ' : 'text/html' } ) ;
95
102
96
103
headers . set ( 'Content-Type' , 'application/json' ) ;
97
- expect ( headers [ 'content-type ' ] ) . to . equal ( 'application/json' ) ;
104
+ expect ( headers [ 'Content-Type ' ] ) . to . equal ( 'application/json' ) ;
98
105
} ) ;
99
106
} ) ;
100
107
101
108
describe ( '#append()' , ( ) => {
102
109
it ( 'should append a value to a non-existent header' , ( ) => {
103
110
const headers = createHeaders ( ) ;
104
111
105
- headers . append ( 'content-type ' , 'application/json' ) ;
106
- expect ( headers [ 'content-type ' ] ) . to . equal ( 'application/json' ) ;
112
+ headers . append ( 'Content-Type ' , 'application/json' ) ;
113
+ expect ( headers [ 'Content-Type ' ] ) . to . equal ( 'application/json' ) ;
107
114
} ) ;
108
115
109
116
it ( 'should convert a single value to an array when appending' , ( ) => {
110
- const headers = createHeaders ( { accept : 'text/html' } ) ;
117
+ const headers = createHeaders ( { Accept : 'text/html' } ) ;
111
118
112
- headers . append ( 'accept ' , 'application/json' ) ;
113
- expect ( headers . accept ) . to . deep . equal ( [ 'text/html' , 'application/json' ] ) ;
119
+ headers . append ( 'Accept ' , 'application/json' ) ;
120
+ expect ( headers . Accept ) . to . deep . equal ( [ 'text/html' , 'application/json' ] ) ;
114
121
} ) ;
115
122
116
123
it ( 'should append to an existing array of values' , ( ) => {
117
- const headers = createHeaders ( { 'set-cookie ' : [ 'cookie1=value1' ] } ) ;
124
+ const headers = createHeaders ( { 'Set-Cookie ' : [ 'cookie1=value1' ] } ) ;
118
125
119
- headers . append ( 'set-cookie ' , 'cookie2=value2' ) ;
120
- expect ( headers [ 'set-cookie ' ] ) . to . deep . equal ( [ 'cookie1=value1' , 'cookie2=value2' ] ) ;
126
+ headers . append ( 'Set-Cookie ' , 'cookie2=value2' ) ;
127
+ expect ( headers [ 'Set-Cookie ' ] ) . to . deep . equal ( [ 'cookie1=value1' , 'cookie2=value2' ] ) ;
121
128
} ) ;
122
129
} ) ;
123
130
124
131
describe ( '#delete()' , ( ) => {
125
132
it ( 'should delete a header' , ( ) => {
126
- const headers = createHeaders ( { 'content-type ' : 'application/json' } ) ;
133
+ const headers = createHeaders ( { 'Content-Type ' : 'application/json' } ) ;
127
134
128
- headers . delete ( 'content-type ' ) ;
129
- expect ( headers [ 'content-type ' ] ) . to . be . undefined ;
130
- expect ( 'content-type ' in headers ) . to . be . false ;
135
+ headers . delete ( 'Content-Type ' ) ;
136
+ expect ( headers [ 'Content-Type ' ] ) . to . be . undefined ;
137
+ expect ( 'Content-Type ' in headers ) . to . be . false ;
131
138
} ) ;
132
139
133
140
it ( 'should handle case-insensitive deletion' , ( ) => {
134
- const headers = createHeaders ( { 'content-type ' : 'application/json' } ) ;
141
+ const headers = createHeaders ( { 'Content-Type ' : 'application/json' } ) ;
135
142
136
143
headers . delete ( 'Content-Type' ) ;
137
144
expect ( 'content-type' in headers ) . to . be . false ;
@@ -141,9 +148,9 @@ describe('Headers', () => {
141
148
describe ( '#forEach()' , ( ) => {
142
149
it ( 'should iterate over all headers' , ( ) => {
143
150
const headers = createHeaders ( {
144
- 'content-type ' : 'application/json' ,
145
- accept : 'text/html' ,
146
- 'x-custom ' : 'custom-value'
151
+ 'Content-Type ' : 'application/json' ,
152
+ Accept : 'text/html' ,
153
+ 'X-Custom ' : 'custom-value'
147
154
} ) ;
148
155
149
156
const result = { } ;
@@ -159,7 +166,7 @@ describe('Headers', () => {
159
166
} ) ;
160
167
161
168
it ( 'should respect thisArg parameter' , ( ) => {
162
- const headers = createHeaders ( { 'content-type ' : 'application/json' } ) ;
169
+ const headers = createHeaders ( { 'Content-Type ' : 'application/json' } ) ;
163
170
const context = { value : 'context' } ;
164
171
165
172
headers . forEach ( function iterator ( ) {
@@ -172,8 +179,8 @@ describe('Headers', () => {
172
179
describe ( 'Iterable Interface' , ( ) => {
173
180
it ( 'should implement entries() iterator' , ( ) => {
174
181
const headers = createHeaders ( {
175
- 'content-type ' : 'application/json' ,
176
- accept : 'text/html'
182
+ 'Content-Type ' : 'application/json' ,
183
+ Accept : 'text/html'
177
184
} ) ;
178
185
179
186
const entries = Array . from ( headers . entries ( ) ) ;
@@ -183,8 +190,8 @@ describe('Headers', () => {
183
190
184
191
it ( 'should implement keys() iterator' , ( ) => {
185
192
const headers = createHeaders ( {
186
- 'content-type ' : 'application/json' ,
187
- accept : 'text/html'
193
+ 'Content-Type ' : 'application/json' ,
194
+ Accept : 'text/html'
188
195
} ) ;
189
196
190
197
const keys = Array . from ( headers . keys ( ) ) ;
@@ -194,8 +201,8 @@ describe('Headers', () => {
194
201
195
202
it ( 'should implement values() iterator' , ( ) => {
196
203
const headers = createHeaders ( {
197
- 'content-type ' : 'application/json' ,
198
- accept : 'text/html'
204
+ 'Content-Type ' : 'application/json' ,
205
+ Accept : 'text/html'
199
206
} ) ;
200
207
201
208
const values = Array . from ( headers . values ( ) ) ;
@@ -205,8 +212,8 @@ describe('Headers', () => {
205
212
206
213
it ( 'should be iterable with Symbol.iterator' , ( ) => {
207
214
const headers = createHeaders ( {
208
- 'content-type ' : 'application/json' ,
209
- accept : 'text/html'
215
+ 'Content-Type ' : 'application/json' ,
216
+ Accept : 'text/html'
210
217
} ) ;
211
218
212
219
const entries = Array . from ( headers ) ;
0 commit comments