Merged branch 'jetty-9.4.x' into 'jetty-10.0.x'.

This commit is contained in:
Simone Bordet 2020-06-01 22:02:59 +02:00
commit 5308adab60
2 changed files with 27 additions and 9 deletions

View File

@ -191,19 +191,18 @@ public abstract class HttpConnection implements IConnection
}
// Cookies
StringBuilder cookies = convertCookies(request.getCookies(), null);
CookieStore cookieStore = getHttpClient().getCookieStore();
if (cookieStore != null && cookieStore.getClass() != HttpCookieStore.Empty.class)
{
StringBuilder cookies = null;
URI uri = request.getURI();
if (uri != null)
cookies = convertCookies(HttpCookieStore.matchPath(uri, cookieStore.get(uri)), null);
cookies = convertCookies(request.getCookies(), cookies);
if (cookies != null)
{
HttpField cookieField = new HttpField(HttpHeader.COOKIE, cookies.toString());
request.addHeader(cookieField);
}
cookies = convertCookies(HttpCookieStore.matchPath(uri, cookieStore.get(uri)), cookies);
}
if (cookies != null)
{
HttpField cookieField = new HttpField(HttpHeader.COOKIE, cookies.toString());
request.addHeader(cookieField);
}
// Authentication

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.client;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.util.Arrays;
@ -34,6 +35,7 @@ import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.HttpCookieStore;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
@ -132,10 +134,22 @@ public class HttpCookieTest extends AbstractHttpClientServerTest
@ParameterizedTest
@ArgumentsSource(ScenarioProvider.class)
public void testPerRequestCookieIsSent(Scenario scenario) throws Exception
{
testPerRequestCookieIsSent(scenario, null);
}
@ParameterizedTest
@ArgumentsSource(ScenarioProvider.class)
public void testPerRequestCookieIsSentWithEmptyCookieStore(Scenario scenario) throws Exception
{
testPerRequestCookieIsSent(scenario, new HttpCookieStore.Empty());
}
private void testPerRequestCookieIsSent(Scenario scenario, CookieStore cookieStore) throws Exception
{
final String name = "foo";
final String value = "bar";
start(scenario, new EmptyServerHandler()
startServer(scenario, new EmptyServerHandler()
{
@Override
protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response)
@ -148,6 +162,11 @@ public class HttpCookieTest extends AbstractHttpClientServerTest
assertEquals(value, cookie.getValue());
}
});
startClient(scenario, client ->
{
if (cookieStore != null)
client.setCookieStore(cookieStore);
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scenario.getScheme())