|
17 | 17 | package org.springframework.boot.autoconfigure.web.embedded;
|
18 | 18 |
|
19 | 19 | import java.io.File;
|
| 20 | +import java.nio.charset.StandardCharsets; |
20 | 21 | import java.util.Arrays;
|
21 | 22 |
|
22 | 23 | import io.undertow.Undertow;
|
23 | 24 | import io.undertow.Undertow.Builder;
|
24 | 25 | import io.undertow.UndertowOptions;
|
25 | 26 | import org.junit.Before;
|
26 | 27 | import org.junit.Test;
|
| 28 | +import org.xnio.Option; |
27 | 29 | import org.xnio.OptionMap;
|
28 | 30 |
|
29 | 31 | import org.springframework.boot.autoconfigure.web.ServerProperties;
|
@@ -88,37 +90,75 @@ public void customizeUndertowAccessLog() {
|
88 | 90 | }
|
89 | 91 |
|
90 | 92 | @Test
|
91 |
| - public void customizeUndertowConnectionCommonSettings() { |
92 |
| - bind("server.undertow.maxParameters=50", "server.undertow.maxHeaders=60", |
93 |
| - "server.undertow.maxCookies=70", "server.undertow.allowEncodedSlash=true", |
94 |
| - "server.undertow.decodeUrl=true", "server.undertow.urlCharset=UTF-8", |
95 |
| - "server.undertow.alwaysSetKeepAlive=true"); |
96 |
| - Builder builder = Undertow.builder(); |
97 |
| - ConfigurableUndertowWebServerFactory factory = mockFactory(builder); |
98 |
| - this.customizer.customize(factory); |
99 |
| - OptionMap map = ((OptionMap.Builder) ReflectionTestUtils.getField(builder, |
100 |
| - "serverOptions")).getMap(); |
101 |
| - assertThat(map.get(UndertowOptions.MAX_PARAMETERS)).isEqualTo(50); |
102 |
| - assertThat(map.get(UndertowOptions.MAX_HEADERS)).isEqualTo(60); |
103 |
| - assertThat(map.get(UndertowOptions.MAX_COOKIES)).isEqualTo(70); |
104 |
| - assertThat(map.get(UndertowOptions.ALLOW_ENCODED_SLASH)).isTrue(); |
105 |
| - assertThat(map.get(UndertowOptions.DECODE_URL)).isTrue(); |
106 |
| - assertThat(map.get(UndertowOptions.URL_CHARSET)).isEqualTo("UTF-8"); |
107 |
| - assertThat(map.get(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isTrue(); |
| 93 | + public void customMaxHttpHeaderSize() { |
| 94 | + bind("server.max-http-header-size=2048"); |
| 95 | + assertThat(boundServerOption(UndertowOptions.MAX_HEADER_SIZE)).isEqualTo(2048); |
108 | 96 | }
|
109 | 97 |
|
110 | 98 | @Test
|
111 |
| - public void customizeUndertowCommonConnectionCommonBoolSettings() { |
112 |
| - bind("server.undertow.allowEncodedSlash=false", "server.undertow.decodeUrl=false", |
113 |
| - "server.undertow.alwaysSetKeepAlive=false"); |
114 |
| - Builder builder = Undertow.builder(); |
115 |
| - ConfigurableUndertowWebServerFactory factory = mockFactory(builder); |
116 |
| - this.customizer.customize(factory); |
117 |
| - OptionMap map = ((OptionMap.Builder) ReflectionTestUtils.getField(builder, |
118 |
| - "serverOptions")).getMap(); |
119 |
| - assertThat(map.get(UndertowOptions.ALLOW_ENCODED_SLASH)).isFalse(); |
120 |
| - assertThat(map.get(UndertowOptions.DECODE_URL)).isFalse(); |
121 |
| - assertThat(map.get(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isFalse(); |
| 99 | + public void customMaxHttpHeaderSizeIgnoredIfNegative() { |
| 100 | + bind("server.max-http-header-size=-1"); |
| 101 | + assertThat(boundServerOption(UndertowOptions.MAX_HEADER_SIZE)).isNull(); |
| 102 | + } |
| 103 | + |
| 104 | + public void customMaxHttpHeaderSizeIgnoredIfZero() { |
| 105 | + bind("server.max-http-header-size=0"); |
| 106 | + assertThat(boundServerOption(UndertowOptions.MAX_HEADER_SIZE)).isNull(); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void customMaxHttpPostSize() { |
| 111 | + bind("server.undertow.max-http-post-size=256"); |
| 112 | + assertThat(boundServerOption(UndertowOptions.MAX_ENTITY_SIZE)).isEqualTo(256); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void customConnectionTimeout() { |
| 117 | + bind("server.connectionTimeout=100"); |
| 118 | + assertThat(boundServerOption(UndertowOptions.NO_REQUEST_TIMEOUT)).isEqualTo(100); |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + public void customMaxParameters() { |
| 123 | + bind("server.undertow.max-parameters=4"); |
| 124 | + assertThat(boundServerOption(UndertowOptions.MAX_PARAMETERS)).isEqualTo(4); |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + public void customMaxHeaders() { |
| 129 | + bind("server.undertow.max-headers=4"); |
| 130 | + assertThat(boundServerOption(UndertowOptions.MAX_HEADERS)).isEqualTo(4); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void customMaxCookies() { |
| 135 | + bind("server.undertow.max-cookies=4"); |
| 136 | + assertThat(boundServerOption(UndertowOptions.MAX_COOKIES)).isEqualTo(4); |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + public void allowEncodedSlashes() { |
| 141 | + bind("server.undertow.allow-encoded-slash=true"); |
| 142 | + assertThat(boundServerOption(UndertowOptions.ALLOW_ENCODED_SLASH)).isTrue(); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + public void disableUrlDecoding() { |
| 147 | + bind("server.undertow.decode-url=false"); |
| 148 | + assertThat(boundServerOption(UndertowOptions.DECODE_URL)).isFalse(); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void customUrlCharset() { |
| 153 | + bind("server.undertow.url-charset=UTF-16"); |
| 154 | + assertThat(boundServerOption(UndertowOptions.URL_CHARSET)) |
| 155 | + .isEqualTo(StandardCharsets.UTF_16.name()); |
| 156 | + } |
| 157 | + |
| 158 | + @Test |
| 159 | + public void disableAlwaysSetKeepAlive() { |
| 160 | + bind("server.undertow.always-set-keep-alive=false"); |
| 161 | + assertThat(boundServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isFalse(); |
122 | 162 | }
|
123 | 163 |
|
124 | 164 | @Test
|
@@ -147,49 +187,13 @@ public void setUseForwardHeaders() {
|
147 | 187 | verify(factory).setUseForwardHeaders(true);
|
148 | 188 | }
|
149 | 189 |
|
150 |
| - @Test |
151 |
| - public void customizeMaxHttpHeaderSize() { |
152 |
| - bind("server.max-http-header-size=2048"); |
153 |
| - Builder builder = Undertow.builder(); |
154 |
| - ConfigurableUndertowWebServerFactory factory = mockFactory(builder); |
155 |
| - this.customizer.customize(factory); |
156 |
| - OptionMap map = ((OptionMap.Builder) ReflectionTestUtils.getField(builder, |
157 |
| - "serverOptions")).getMap(); |
158 |
| - assertThat(map.get(UndertowOptions.MAX_HEADER_SIZE).intValue()).isEqualTo(2048); |
159 |
| - } |
160 |
| - |
161 |
| - @Test |
162 |
| - public void customMaxHttpHeaderSizeIgnoredIfNegative() { |
163 |
| - bind("server.max-http-header-size=-1"); |
164 |
| - Builder builder = Undertow.builder(); |
165 |
| - ConfigurableUndertowWebServerFactory factory = mockFactory(builder); |
166 |
| - this.customizer.customize(factory); |
167 |
| - OptionMap map = ((OptionMap.Builder) ReflectionTestUtils.getField(builder, |
168 |
| - "serverOptions")).getMap(); |
169 |
| - assertThat(map.contains(UndertowOptions.MAX_HEADER_SIZE)).isFalse(); |
170 |
| - } |
171 |
| - |
172 |
| - @Test |
173 |
| - public void customMaxHttpHeaderSizeIgnoredIfZero() { |
174 |
| - bind("server.max-http-header-size=0"); |
175 |
| - Builder builder = Undertow.builder(); |
176 |
| - ConfigurableUndertowWebServerFactory factory = mockFactory(builder); |
177 |
| - this.customizer.customize(factory); |
178 |
| - OptionMap map = ((OptionMap.Builder) ReflectionTestUtils.getField(builder, |
179 |
| - "serverOptions")).getMap(); |
180 |
| - assertThat(map.contains(UndertowOptions.MAX_HEADER_SIZE)).isFalse(); |
181 |
| - } |
182 |
| - |
183 |
| - @Test |
184 |
| - public void customConnectionTimeout() { |
185 |
| - bind("server.connection-timeout=100"); |
| 190 | + private <T> T boundServerOption(Option<T> option) { |
186 | 191 | Builder builder = Undertow.builder();
|
187 | 192 | ConfigurableUndertowWebServerFactory factory = mockFactory(builder);
|
188 | 193 | this.customizer.customize(factory);
|
189 | 194 | OptionMap map = ((OptionMap.Builder) ReflectionTestUtils.getField(builder,
|
190 | 195 | "serverOptions")).getMap();
|
191 |
| - assertThat(map.contains(UndertowOptions.NO_REQUEST_TIMEOUT)).isTrue(); |
192 |
| - assertThat(map.get(UndertowOptions.NO_REQUEST_TIMEOUT)).isEqualTo(100); |
| 196 | + return map.get(option); |
193 | 197 | }
|
194 | 198 |
|
195 | 199 | private ConfigurableUndertowWebServerFactory mockFactory(Builder builder) {
|
|
0 commit comments