419901 - Client always adds extra user-agent header.
Added test case.
This commit is contained in:
parent
3f852cf3db
commit
b46af29a42
|
@ -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<String> 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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue