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

View File

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