From b46af29a42a12ec33764ed47719133c78d58b86f Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 21 Oct 2013 10:28:34 +0200 Subject: [PATCH 1/2] 419901 - Client always adds extra user-agent header. Added test case. --- .../eclipse/jetty/client/HttpClientTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java index aa7db6bc72b..02d800021d7 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java @@ -28,7 +28,9 @@ import java.nio.channels.UnresolvedAddressException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; @@ -824,4 +826,29 @@ public class HttpClientTest extends AbstractHttpClientServerTest }); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); } + + @Test + public void testCustomUserAgent() throws Exception + { + final String userAgent = "Test/1.0"; + start(new AbstractHandler() + { + @Override + public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + { + baseRequest.setHandled(true); + ArrayList userAgents = Collections.list(request.getHeaders("User-Agent")); + Assert.assertEquals(1, userAgents.size()); + Assert.assertEquals(userAgent, userAgents.get(0)); + } + }); + + ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) + .agent(userAgent) + .timeout(5, TimeUnit.SECONDS) + .send(); + + Assert.assertEquals(200, response.getStatus()); + } } From 7520389c91215ad515e62d8b92e2dbe50c1b5a85 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 21 Oct 2013 10:39:06 +0200 Subject: [PATCH 2/2] 419901 - Client always adds extra user-agent header. Improved test case. --- .../java/org/eclipse/jetty/client/HttpClientTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java index 02d800021d7..9d80ad3b722 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java @@ -54,6 +54,7 @@ import org.eclipse.jetty.client.api.Response; import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.client.util.BytesContentProvider; import org.eclipse.jetty.http.HttpField; +import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; @@ -850,5 +851,13 @@ public class HttpClientTest extends AbstractHttpClientServerTest .send(); Assert.assertEquals(200, response.getStatus()); + + response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) + .header(HttpHeader.USER_AGENT, userAgent) + .timeout(5, TimeUnit.SECONDS) + .send(); + + Assert.assertEquals(200, response.getStatus()); } }