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());
|
headers.put(getHttpDestination().getHostField());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.getAgent() == null)
|
|
||||||
headers.put(getHttpClient().getUserAgentField());
|
|
||||||
|
|
||||||
// Add content headers
|
// Add content headers
|
||||||
if (content != null)
|
if (content != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,6 +94,9 @@ public class HttpRequest implements Request
|
||||||
HttpField acceptEncodingField = client.getAcceptEncodingField();
|
HttpField acceptEncodingField = client.getAcceptEncodingField();
|
||||||
if (acceptEncodingField != null)
|
if (acceptEncodingField != null)
|
||||||
headers.put(acceptEncodingField);
|
headers.put(acceptEncodingField);
|
||||||
|
HttpField userAgentField = client.getUserAgentField();
|
||||||
|
if (userAgentField != null)
|
||||||
|
headers.put(userAgentField);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpConversation getConversation()
|
protected HttpConversation getConversation()
|
||||||
|
@ -238,8 +241,7 @@ public class HttpRequest implements Request
|
||||||
@Override
|
@Override
|
||||||
public Request agent(String agent)
|
public Request agent(String agent)
|
||||||
{
|
{
|
||||||
headers.put(HttpHeader.USER_AGENT, agent);
|
return header(HttpHeader.USER_AGENT, agent);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -854,6 +854,51 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
Assert.assertEquals(200, response.getStatus());
|
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
|
@Test
|
||||||
public void testRequestListenerForMultipleEventsIsInvokedOncePerEvent() throws Exception
|
public void testRequestListenerForMultipleEventsIsInvokedOncePerEvent() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue