16
16
17
17
package org .springframework .web .servlet .resource ;
18
18
19
- import static org .junit .Assert .*;
20
-
21
19
import java .io .IOException ;
22
20
import java .text .SimpleDateFormat ;
23
21
import java .util .ArrayList ;
26
24
import java .util .List ;
27
25
import java .util .Locale ;
28
26
import java .util .TimeZone ;
29
-
30
27
import javax .servlet .http .HttpServletResponse ;
31
28
32
29
import org .hamcrest .Matchers ;
48
45
import org .springframework .web .accept .ContentNegotiationManagerFactoryBean ;
49
46
import org .springframework .web .servlet .HandlerMapping ;
50
47
48
+ import static org .junit .Assert .*;
49
+
51
50
/**
52
51
* Unit tests for ResourceHttpRequestHandler.
53
52
*
@@ -97,6 +96,8 @@ public void getResource() throws Exception {
97
96
assertEquals ("max-age=3600" , this .response .getHeader ("Cache-Control" ));
98
97
assertTrue (this .response .containsHeader ("Last-Modified" ));
99
98
assertEquals (this .response .getHeader ("Last-Modified" ), resourceLastModifiedDate ("test/foo.css" ));
99
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
100
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
100
101
assertEquals ("h1 { color:red; }" , this .response .getContentAsString ());
101
102
}
102
103
@@ -112,6 +113,8 @@ public void getResourceHttpHeader() throws Exception {
112
113
assertEquals ("max-age=3600" , this .response .getHeader ("Cache-Control" ));
113
114
assertTrue (this .response .containsHeader ("Last-Modified" ));
114
115
assertEquals (this .response .getHeader ("Last-Modified" ), resourceLastModifiedDate ("test/foo.css" ));
116
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
117
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
115
118
assertEquals (0 , this .response .getContentAsByteArray ().length );
116
119
}
117
120
@@ -134,6 +137,8 @@ public void getResourceNoCache() throws Exception {
134
137
assertEquals ("no-store" , this .response .getHeader ("Cache-Control" ));
135
138
assertTrue (this .response .containsHeader ("Last-Modified" ));
136
139
assertEquals (this .response .getHeader ("Last-Modified" ), resourceLastModifiedDate ("test/foo.css" ));
140
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
141
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
137
142
}
138
143
139
144
@ Test
@@ -147,6 +152,8 @@ public void getVersionedResource() throws Exception {
147
152
this .handler .handleRequest (this .request , this .response );
148
153
149
154
assertEquals ("\" versionString\" " , this .response .getHeader ("ETag" ));
155
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
156
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
150
157
}
151
158
152
159
@ Test
@@ -163,6 +170,8 @@ public void getResourceHttp10BehaviorCache() throws Exception {
163
170
assertTrue (dateHeaderAsLong ("Expires" ) >= System .currentTimeMillis () - 1000 + (3600 * 1000 ));
164
171
assertTrue (this .response .containsHeader ("Last-Modified" ));
165
172
assertEquals (this .response .getHeader ("Last-Modified" ), resourceLastModifiedDate ("test/foo.css" ));
173
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
174
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
166
175
}
167
176
168
177
@ Test
@@ -181,6 +190,8 @@ public void getResourceHttp10BehaviorNoCache() throws Exception {
181
190
assertTrue (dateHeaderAsLong ("Expires" ) <= System .currentTimeMillis ());
182
191
assertTrue (this .response .containsHeader ("Last-Modified" ));
183
192
assertEquals (dateHeaderAsLong ("Last-Modified" ) / 1000 , resourceLastModified ("test/foo.css" ) / 1000 );
193
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
194
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
184
195
}
185
196
186
197
@ Test
@@ -192,6 +203,8 @@ public void getResourceWithHtmlMediaType() throws Exception {
192
203
assertEquals ("max-age=3600" , this .response .getHeader ("Cache-Control" ));
193
204
assertTrue (this .response .containsHeader ("Last-Modified" ));
194
205
assertEquals (this .response .getHeader ("Last-Modified" ), resourceLastModifiedDate ("test/foo.html" ));
206
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
207
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
195
208
}
196
209
197
210
@ Test
@@ -204,6 +217,8 @@ public void getResourceFromAlternatePath() throws Exception {
204
217
assertEquals ("max-age=3600" , this .response .getHeader ("Cache-Control" ));
205
218
assertTrue (this .response .containsHeader ("Last-Modified" ));
206
219
assertEquals (this .response .getHeader ("Last-Modified" ), resourceLastModifiedDate ("testalternatepath/baz.css" ));
220
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
221
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
207
222
assertEquals ("h1 { color:red; }" , this .response .getContentAsString ());
208
223
}
209
224
@@ -455,6 +470,8 @@ public void partialContentByteRange() throws Exception {
455
470
assertEquals (2 , this .response .getContentLength ());
456
471
assertEquals ("bytes 0-1/10" , this .response .getHeader ("Content-Range" ));
457
472
assertEquals ("So" , this .response .getContentAsString ());
473
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
474
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
458
475
}
459
476
460
477
@ Test
@@ -468,6 +485,8 @@ public void partialContentByteRangeNoEnd() throws Exception {
468
485
assertEquals (1 , this .response .getContentLength ());
469
486
assertEquals ("bytes 9-9/10" , this .response .getHeader ("Content-Range" ));
470
487
assertEquals ("." , this .response .getContentAsString ());
488
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
489
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
471
490
}
472
491
473
492
@ Test
@@ -481,6 +500,8 @@ public void partialContentByteRangeLargeEnd() throws Exception {
481
500
assertEquals (1 , this .response .getContentLength ());
482
501
assertEquals ("bytes 9-9/10" , this .response .getHeader ("Content-Range" ));
483
502
assertEquals ("." , this .response .getContentAsString ());
503
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
504
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
484
505
}
485
506
486
507
@ Test
@@ -494,6 +515,8 @@ public void partialContentSuffixRange() throws Exception {
494
515
assertEquals (1 , this .response .getContentLength ());
495
516
assertEquals ("bytes 9-9/10" , this .response .getHeader ("Content-Range" ));
496
517
assertEquals ("." , this .response .getContentAsString ());
518
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
519
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
497
520
}
498
521
499
522
@ Test
@@ -507,6 +530,8 @@ public void partialContentSuffixRangeLargeSuffix() throws Exception {
507
530
assertEquals (10 , this .response .getContentLength ());
508
531
assertEquals ("bytes 0-9/10" , this .response .getHeader ("Content-Range" ));
509
532
assertEquals ("Some text." , this .response .getContentAsString ());
533
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
534
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
510
535
}
511
536
512
537
@ Test
@@ -517,6 +542,8 @@ public void partialContentInvalidRangeHeader() throws Exception {
517
542
518
543
assertEquals (416 , this .response .getStatus ());
519
544
assertEquals ("bytes */10" , this .response .getHeader ("Content-Range" ));
545
+ assertEquals ("bytes" , this .response .getHeader ("Accept-Ranges" ));
546
+ assertEquals (1 , this .response .getHeaders ("Accept-Ranges" ).size ());
520
547
}
521
548
522
549
@ Test
0 commit comments