Fixes #1069 - Host header should be sent with HTTP/1.0.

This commit is contained in:
Simone Bordet 2016-11-04 09:53:22 +01:00
parent fba901d156
commit d18b900b75
2 changed files with 24 additions and 3 deletions

View File

@ -113,7 +113,7 @@ public abstract class HttpConnection implements Connection
} }
// If we are HTTP 1.1, add the Host header // If we are HTTP 1.1, add the Host header
if (version.getVersion() == 11) if (version.getVersion() <= 11)
{ {
if (!headers.containsKey(HttpHeader.HOST.asString())) if (!headers.containsKey(HttpHeader.HOST.asString()))
headers.put(getHttpDestination().getHostField()); headers.put(getHttpDestination().getHostField());

View File

@ -1562,8 +1562,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
} }
@Test @Test
public void testCopyRequest() public void testCopyRequest() throws Exception
throws Exception
{ {
startClient(); startClient();
@ -1610,6 +1609,28 @@ public class HttpClientTest extends AbstractHttpClientServerTest
.header("X-Custom-Header-2", "value")); .header("X-Custom-Header-2", "value"));
} }
@Test
public void testHostWithHTTP10() 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);
Assert.assertThat(request.getHeader("Host"), Matchers.notNullValue());
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.version(HttpVersion.HTTP_1_0)
.timeout(5, TimeUnit.SECONDS)
.send();
Assert.assertEquals(200, response.getStatus());
}
private void assertCopyRequest(Request original) private void assertCopyRequest(Request original)
{ {
Request copy = client.copyRequest((HttpRequest) original, original.getURI()); Request copy = client.copyRequest((HttpRequest) original, original.getURI());