Skip to content

Commit 68f308f

Browse files
authored
Merge pull request #1821 from fl4via/backport-features_2.4.x
[UNDERTOW-2634 / 1901 / 1870 / 1904 / 2254 / 2249] Backport features to 2.4.x
2 parents 50ab1da + 3f5e19f commit 68f308f

File tree

13 files changed

+91
-15
lines changed

13 files changed

+91
-15
lines changed

core/src/main/java/io/undertow/client/ajp/AjpClientConnection.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ public void sendRequest(final ClientRequest request, final ClientCallback<Client
237237
clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState());
238238
return;
239239
}
240+
if (anyAreSet(state, CLOSE_REQ | CLOSED)) {
241+
clientCallback.failed(new ClosedChannelException());
242+
return;
243+
}
240244
final AjpClientExchange AjpClientExchange = new AjpClientExchange(clientCallback, request, this);
241245
if (currentRequest == null) {
242246
initiateRequest(AjpClientExchange);

core/src/main/java/io/undertow/client/http/HttpClientConnection.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ public void sendRequest(final ClientRequest request, final ClientCallback<Client
352352
clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState());
353353
return;
354354
}
355+
if (anyAreSet(state, CLOSE_REQ | CLOSED)) {
356+
clientCallback.failed(new ClosedChannelException());
357+
return;
358+
}
355359
final HttpClientExchange httpClientExchange = new HttpClientExchange(clientCallback, request, this);
356360
boolean ssl = this.connection instanceof SslConnection;
357361
if(!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, false) && !request.getRequestHeaders().contains(Headers.UPGRADE)) {

core/src/main/java/io/undertow/server/HttpServerExchange.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import io.undertow.util.ConduitFactory;
4141
import io.undertow.util.Cookies;
4242
import io.undertow.util.HeaderMap;
43+
import io.undertow.util.HeaderValues;
4344
import io.undertow.util.Headers;
4445
import io.undertow.util.HttpString;
4546
import io.undertow.util.Methods;
@@ -1929,6 +1930,16 @@ public XnioIoThread getIoThread() {
19291930
return connection.getIoThread();
19301931
}
19311932

1933+
public boolean isMultiPartExchange() {
1934+
//NOTE: should this include Range response?
1935+
final HeaderValues contentTypeHeaders = getRequestHeaders().get("Content-Type");
1936+
if(contentTypeHeaders != null && contentTypeHeaders.size() >0) {
1937+
return contentTypeHeaders.getFirst().startsWith("multipart");
1938+
} else {
1939+
return false;
1940+
}
1941+
}
1942+
19321943
/**
19331944
* @return The maximum entity size for this exchange
19341945
*/

core/src/main/java/io/undertow/server/handlers/proxy/LoadBalancingProxyClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ protected Host selectHost(HttpServerExchange exchange) {
360360
}
361361
}
362362

363-
int host = hostSelector.selectHost(hosts);
363+
int host = hostSelector.selectHost(hosts, exchange);
364364

365365
final int startHost = host; //if the all hosts have problems we come back to this one
366366
Host full = null;
@@ -473,16 +473,27 @@ private static class ExclusiveConnectionHolder {
473473

474474
public interface HostSelector {
475475

476+
@Deprecated(forRemoval = true)
476477
int selectHost(Host[] availableHosts);
478+
479+
int selectHost(Host[] availableHosts, HttpServerExchange exchange);
480+
477481
}
478482

479483
static class RoundRobinHostSelector implements HostSelector {
480484

481485
private final AtomicInteger currentHost = new AtomicInteger(0);
482486

483487
@Override
488+
@Deprecated(forRemoval = true)
484489
public int selectHost(Host[] availableHosts) {
485490
return currentHost.incrementAndGet() % availableHosts.length;
486491
}
492+
493+
@Override
494+
public int selectHost(Host[] availableHosts, HttpServerExchange exchange) {
495+
return selectHost(availableHosts);
496+
}
497+
487498
}
488499
}

core/src/main/java/io/undertow/server/session/InMemorySessionManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,5 +671,10 @@ private synchronized void destroy() {
671671
cancelTask = null;
672672
}
673673

674+
@Override
675+
public boolean isInvalid() {
676+
return this.invalid;
677+
}
678+
674679
}
675680
}

core/src/main/java/io/undertow/server/session/Session.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,10 @@ public interface Session {
183183
* @return The new session ID
184184
*/
185185
String changeSessionId(HttpServerExchange exchange, SessionConfig config);
186+
187+
/**
188+
* Return state of session. NOTE: this method does not take into account if process of invalidation start.
189+
* @return <ul><li><b>true</b> - if session is no longer valid</li><li><b>false</b> - otherwise</li></ul>
190+
*/
191+
boolean isInvalid();
186192
}

core/src/main/java/io/undertow/util/MimeMappings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class MimeMappings {
3838
Map<String, String> defaultMappings = new HashMap<>(101);
3939
defaultMappings.put("txt", "text/plain");
4040
defaultMappings.put("css", "text/css");
41+
defaultMappings.put("csv", "text/csv");
4142
defaultMappings.put("html", "text/html");
4243
defaultMappings.put("htm", "text/html");
4344
defaultMappings.put("gif", "image/gif");
@@ -119,6 +120,10 @@ public class MimeMappings {
119120
defaultMappings.put("mpeg", "video/mpeg");
120121
defaultMappings.put("mpg", "video/mpeg");
121122
defaultMappings.put("mpe", "video/mpeg");
123+
defaultMappings.put("mp4", "video/mp4");
124+
defaultMappings.put("webm", "video/webm");
125+
defaultMappings.put("flac", "audio/flac");
126+
defaultMappings.put("weba", "audio/webm");
122127
defaultMappings.put("qt", "video/quicktime");
123128
defaultMappings.put("mov", "video/quicktime");
124129
defaultMappings.put("avi", "video/x-msvideo");
@@ -127,7 +132,6 @@ public class MimeMappings {
127132
defaultMappings.put("wrl", "x-world/x-vrml");
128133
defaultMappings.put("mpv2", "video/mpeg2");
129134
defaultMappings.put("jnlp", "application/x-java-jnlp-file");
130-
131135
defaultMappings.put("eot", "application/vnd.ms-fontobject");
132136
defaultMappings.put("woff", "application/font-woff");
133137
defaultMappings.put("woff2", "application/font-woff2");

core/src/test/java/io/undertow/server/handlers/proxy/LoadBalancingProxyWithCustomHostSelectorTestCase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.undertow.Undertow;
44
import io.undertow.client.UndertowClient;
5+
import io.undertow.server.HttpServerExchange;
56
import io.undertow.server.session.InMemorySessionManager;
67
import io.undertow.server.session.SessionAttachmentHandler;
78
import io.undertow.server.session.SessionCookieConfig;
@@ -53,10 +54,17 @@ public static void setup() throws URISyntaxException {
5354
server2.start();
5455

5556
LoadBalancingProxyClient.HostSelector hostSelector = new LoadBalancingProxyClient.HostSelector() {
57+
5658
@Override
5759
public int selectHost(LoadBalancingProxyClient.Host[] availableHosts) {
5860
return 0;
5961
}
62+
63+
@Override
64+
public int selectHost(LoadBalancingProxyClient.Host[] availableHosts, HttpServerExchange exchange) {
65+
return 0;
66+
}
67+
6068
};
6169

6270
DefaultServer.setRootHandler(ProxyHandler.builder().setProxyClient(new LoadBalancingProxyClient(UndertowClient.getInstance(), null, hostSelector)

servlet/src/main/java/io/undertow/servlet/api/DeploymentInfo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class DeploymentInfo implements Cloneable {
8686
private ConfidentialPortManager confidentialPortManager;
8787
private boolean allowNonStandardWrappers = false;
8888
private int defaultSessionTimeout = 60 * 30;
89+
private long defaultAsyncContextTimeout = 30000;
8990
private ConcurrentMap<String, Object> servletContextAttributeBackingMap;
9091
private ServletSessionConfig servletSessionConfig;
9192
private String hostName = "localhost";
@@ -319,6 +320,18 @@ public DeploymentInfo setDefaultSessionTimeout(final int defaultSessionTimeout)
319320
return this;
320321
}
321322

323+
public long getDefaultAsyncConextTimeout() {
324+
return defaultAsyncContextTimeout;
325+
}
326+
327+
/**
328+
* @param defaultAsyncContextTimeout The default async context timeout, in milliseconds
329+
*/
330+
public DeploymentInfo setDefaultAsyncConextTimeout(final long defaultAsyncContextTimeout) {
331+
this.defaultAsyncContextTimeout = defaultAsyncContextTimeout;
332+
return this;
333+
}
334+
322335
public String getDefaultEncoding() {
323336
return defaultEncoding;
324337
}
@@ -1468,6 +1481,7 @@ public DeploymentInfo clone() {
14681481
info.notificationReceivers.addAll(notificationReceivers);
14691482
info.allowNonStandardWrappers = allowNonStandardWrappers;
14701483
info.defaultSessionTimeout = defaultSessionTimeout;
1484+
info.defaultAsyncContextTimeout = defaultAsyncContextTimeout;
14711485
info.servletContextAttributeBackingMap = servletContextAttributeBackingMap;
14721486
info.servletSessionConfig = servletSessionConfig;
14731487
info.hostName = hostName;

servlet/src/main/java/io/undertow/servlet/core/ManagedServlet.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,22 @@ public ServletInfo getServletInfo() {
232232

233233
/**
234234
* This value determines max multipart message size
235+
* @deprecated
236+
* @see #getMaxMultipartRequestSize()
235237
* @return
236238
*/
237239
public long getMaxRequestSize() {
238240
return maxMultipartRequestSize;
239241
}
240242

243+
/**
244+
* This value determines max multipart message size
245+
* @return
246+
*/
247+
public long getMaxMultipartRequestSize() {
248+
return maxMultipartRequestSize;
249+
}
250+
241251
public FormParserFactory getFormParserFactory() {
242252
return formParserFactory;
243253
}

0 commit comments

Comments
 (0)