|
34 | 34 | *
|
35 | 35 | * @author Rossen Stoyanchev
|
36 | 36 | * @author Juergen Hoeller
|
| 37 | + * @author Sam Brannen |
37 | 38 | */
|
38 | 39 | class HeaderContentNegotiationStrategyTests {
|
39 | 40 |
|
@@ -63,6 +64,27 @@ void resolveMediaTypesFromMultipleHeaderValues() throws Exception {
|
63 | 64 | .containsExactly("text/html", "text/x-c", "text/x-dvi;q=0.8", "text/plain;q=0.5");
|
64 | 65 | }
|
65 | 66 |
|
| 67 | + @Test // gh-32483 |
| 68 | + void resolveMediaTypesWithMaxElements() throws Exception { |
| 69 | + String acceptHeaderValue = "text/plain, text/html,".repeat(25); |
| 70 | + this.servletRequest.addHeader("Accept", acceptHeaderValue); |
| 71 | + List<MediaType> mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); |
| 72 | + |
| 73 | + assertThat(mediaTypes).hasSize(50); |
| 74 | + assertThat(mediaTypes.stream().map(Object::toString).distinct()) |
| 75 | + .containsExactly("text/plain", "text/html"); |
| 76 | + } |
| 77 | + |
| 78 | + @Test // gh-32483 |
| 79 | + void resolveMediaTypesWithTooManyElements() { |
| 80 | + String acceptHeaderValue = "text/plain,".repeat(51); |
| 81 | + this.servletRequest.addHeader("Accept", acceptHeaderValue); |
| 82 | + assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class) |
| 83 | + .isThrownBy(() -> this.strategy.resolveMediaTypes(this.webRequest)) |
| 84 | + .withMessageStartingWith("Could not parse 'Accept' header") |
| 85 | + .withMessageEndingWith("Too many elements"); |
| 86 | + } |
| 87 | + |
66 | 88 | @Test
|
67 | 89 | void resolveMediaTypesParseError() {
|
68 | 90 | this.servletRequest.addHeader("Accept", "textplain; q=0.5");
|
|
0 commit comments