Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-10-16 14:00:22 +11:00
commit 8f1975cc04
13 changed files with 199 additions and 17 deletions

View File

@ -1,5 +1,5 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=WARN
org.eclipse.jetty.LEVEL=INFO
org.eclipse.jetty.embedded.JettyDistribution.LEVEL=DEBUG
#org.eclipse.jetty.STACKS=true
#org.eclipse.jetty.STACKS=false

View File

@ -39,6 +39,11 @@ public class WindowRateControl implements RateControl
private final int maxEvents;
private final long window;
public static WindowRateControl fromEventsPerSecond(int maxEvents)
{
return new WindowRateControl(maxEvents, Duration.ofSeconds(1));
}
public WindowRateControl(int maxEvents, Duration window)
{
this.maxEvents = maxEvents;

View File

@ -12,6 +12,12 @@
<Set name="maxConcurrentStreams" property="jetty.http2.maxConcurrentStreams"/>
<Set name="initialStreamRecvWindow" property="jetty.http2.initialStreamRecvWindow"/>
<Set name="initialSessionRecvWindow" property="jetty.http2.initialSessionRecvWindow"/>
<Set name="maxSettingsKeys"><Property name="jetty.http2.maxSettingsKeys" default="64"/></Set>
<Set name="rateControl">
<Call class="org.eclipse.jetty.http2.parser.WindowRateControl" name="fromEventsPerSecond">
<Arg type="int"><Property name="jetty.http2.rateControl.maxEventsPerSecond" default="20"/></Arg>
</Call>
</Set>
</New>
</Arg>
</Call>

View File

@ -11,6 +11,12 @@
<Arg name="config"><Ref refid="httpConfig"/></Arg>
<Set name="maxConcurrentStreams" property="jetty.http2c.maxConcurrentStreams"/>
<Set name="initialStreamRecvWindow" property="jetty.http2c.initialStreamRecvWindow"/>
<Set name="maxSettingsKeys"><Property name="jetty.http2.maxSettingsKeys" default="64"/></Set>
<Set name="rateControl">
<Call class="org.eclipse.jetty.http2.parser.WindowRateControl" name="fromEventsPerSecond">
<Arg type="int"><Property name="jetty.http2.rateControl.maxEventsPerSecond" default="20"/></Arg>
</Call>
</Set>
</New>
</Arg>
</Call>

View File

@ -29,3 +29,9 @@ etc/jetty-http2.xml
## Initial session receive window (client to server)
# jetty.http2.initialSessionRecvWindow=1048576
## The max number of keys in all SETTINGS frames
# jetty.http2.maxSettingsKeys=64
## Max number of bad frames and pings per second
# jetty.http2.rateControl.maxEventsPerSecond=20

View File

@ -24,3 +24,9 @@ etc/jetty-http2c.xml
## Initial stream receive window (client to server)
# jetty.http2c.initialStreamRecvWindow=65535
## The max number of keys in all SETTINGS frames
# jetty.http2.maxSettingsKeys=64
## Max number of bad frames and pings per second
# jetty.http2.rateControl.maxEventsPerSecond=20

View File

@ -1539,7 +1539,8 @@ public class Request implements HttpServletRequest
if (sessionHandler == ss.getSessionHandler())
{
session = s;
break;
if (ss.isValid())
return session;
}
}
return session;

View File

@ -1511,19 +1511,22 @@ public class SessionHandler extends ScopedHandler
oldSessionHandler = baseRequest.getSessionHandler();
oldSession = baseRequest.getSession(false);
//find any existing session for this request that has already been accessed
existingSession = baseRequest.getSession(this);
if (existingSession == null)
if (oldSessionHandler != this)
{
//session for this context has not been visited previously,
//try getting it
baseRequest.setSession(null);
checkRequestedSessionId(baseRequest, request);
existingSession = baseRequest.getSession(false);
}
//find any existing session for this request that has already been accessed
existingSession = baseRequest.getSession(this);
if (existingSession == null)
{
//session for this context has not been visited previously,
//try getting it
baseRequest.setSession(null);
checkRequestedSessionId(baseRequest, request);
existingSession = baseRequest.getSession(false);
}
baseRequest.setSession(existingSession);
baseRequest.setSessionHandler(this);
baseRequest.setSession(existingSession);
baseRequest.setSessionHandler(this);
}
break;
}
default:

View File

@ -1,5 +1,5 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=WARN
org.eclipse.jetty.LEVEL=INFO
#org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG
#org.eclipse.jetty.server.ConnectionLimit.LEVEL=DEBUG

View File

@ -1,5 +1,5 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=WARN
org.eclipse.jetty.LEVEL=INFO
#org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG
#org.eclipse.jetty.servlet.LEVEL=DEBUG

View File

@ -471,7 +471,10 @@ public class MultiMapTest
mm.putValues("food", "apple", "cherry", "raspberry");
assertEquals("{color=red, food=[apple, cherry, raspberry]}", mm.toString());
String expected1 = "{color=red, food=[apple, cherry, raspberry]}";
String expected2 = "{food=[apple, cherry, raspberry], color=red}";
String actual = mm.toString();
assertTrue(actual.equals(expected1) || actual.equals(expected2));
}
/**

View File

@ -1,4 +1,4 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=WARN
org.eclipse.jetty.LEVEL=INFO
#org.eclipse.jetty.LEVEL=DEBUG
#org.eclipse.jetty.websocket.LEVEL=DEBUG

View File

@ -0,0 +1,146 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.util.FormContentProvider;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class RequestDispatchedSessionTest
{
private Server server;
private HttpClient client;
@BeforeEach
public void startServer() throws Exception
{
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
// Default session behavior
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
contextHandler.addServlet(LoginServlet.class, "/login");
contextHandler.addServlet(ShowUserServlet.class, "/user");
contextHandler.addServlet(DefaultServlet.class, "/");
HandlerList handlers = new HandlerList();
handlers.addHandler(contextHandler);
handlers.addHandler(new DefaultHandler());
server.setHandler(handlers);
server.start();
}
@AfterEach
public void stopServerAndClient()
{
LifeCycle.stop(server);
LifeCycle.stop(client);
}
@BeforeEach
public void startClient() throws Exception
{
client = new HttpClient();
client.start();
}
@Test
public void testRedirect() throws Exception
{
Fields postForm = new Fields();
postForm.add("username", "whizbat");
ContentResponse response = client.newRequest(server.getURI().resolve("/login"))
.method(HttpMethod.POST)
.content(new FormContentProvider(postForm))
.send();
assertThat("Response status", response.getStatus(), is(HttpStatus.OK_200));
}
public static class LoginServlet extends HttpServlet
{
public static final String USERNAME = "loggedInUserName";
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
if (request.getParameter("username") != null)
{
if (request.getSession() != null)
{
request.getSession().invalidate();
}
request.getSession(true).setAttribute(USERNAME, request.getParameter("username"));
request.getRequestDispatcher("/user").forward(request, response);
return;
}
}
}
public static class ShowUserServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
showUser(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
showUser(req, resp);
}
private void showUser(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
resp.setContentType("text/plain");
resp.setCharacterEncoding("utf-8");
PrintWriter out = resp.getWriter();
String userName = (String)req.getSession().getAttribute(LoginServlet.USERNAME);
out.printf("UserName is %s%n", userName);
}
}
}