Merged branch 'jetty-9.2.x' into 'master'.
This commit is contained in:
commit
65832dfae3
|
@ -105,9 +105,6 @@ public abstract class HttpConnection implements Connection
|
|||
headers.put(getHttpDestination().getHostField());
|
||||
}
|
||||
|
||||
if (request.getAgent() == null)
|
||||
headers.put(getHttpClient().getUserAgentField());
|
||||
|
||||
// Add content headers
|
||||
if (content != null)
|
||||
{
|
||||
|
|
|
@ -94,6 +94,9 @@ public class HttpRequest implements Request
|
|||
HttpField acceptEncodingField = client.getAcceptEncodingField();
|
||||
if (acceptEncodingField != null)
|
||||
headers.put(acceptEncodingField);
|
||||
HttpField userAgentField = client.getUserAgentField();
|
||||
if (userAgentField != null)
|
||||
headers.put(userAgentField);
|
||||
}
|
||||
|
||||
protected HttpConversation getConversation()
|
||||
|
@ -238,8 +241,7 @@ public class HttpRequest implements Request
|
|||
@Override
|
||||
public Request agent(String agent)
|
||||
{
|
||||
headers.put(HttpHeader.USER_AGENT, agent);
|
||||
return this;
|
||||
return header(HttpHeader.USER_AGENT, agent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -854,6 +854,51 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
|||
Assert.assertEquals(200, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserAgentCanBeRemoved() throws Exception
|
||||
{
|
||||
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"));
|
||||
if ("/ua".equals(target))
|
||||
Assert.assertEquals(1, userAgents.size());
|
||||
else
|
||||
Assert.assertEquals(0, userAgents.size());
|
||||
}
|
||||
});
|
||||
|
||||
// User agent not specified, use default.
|
||||
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.path("/ua")
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
|
||||
Assert.assertEquals(200, response.getStatus());
|
||||
|
||||
// User agent explicitly removed.
|
||||
response = client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.agent(null)
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
|
||||
Assert.assertEquals(200, response.getStatus());
|
||||
|
||||
// User agent explicitly removed.
|
||||
response = client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.header(HttpHeader.USER_AGENT, null)
|
||||
.timeout(5, TimeUnit.SECONDS)
|
||||
.send();
|
||||
|
||||
Assert.assertEquals(200, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestListenerForMultipleEventsIsInvokedOncePerEvent() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue