486589 - HttpRequest has a wrong HTTP Version in HTTP/2.

This commit is contained in:
Simone Bordet 2016-02-10 15:04:36 +01:00
parent 6306f06e2f
commit a1a8f6aeae
2 changed files with 34 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import org.eclipse.jetty.client.HttpConnection;
import org.eclipse.jetty.client.HttpDestination;
import org.eclipse.jetty.client.HttpExchange;
import org.eclipse.jetty.client.SendFailure;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http2.ErrorCode;
import org.eclipse.jetty.http2.api.Session;
import org.eclipse.jetty.util.Callback;
@ -50,6 +51,7 @@ public class HttpConnectionOverHTTP2 extends HttpConnection
@Override
protected SendFailure send(HttpExchange exchange)
{
exchange.getRequest().version(HttpVersion.HTTP_2);
normalizeRequest(exchange.getRequest());
// One connection maps to N channels, so for each exchange we create a new channel.

View File

@ -18,12 +18,17 @@
package org.eclipse.jetty.http2.client.http;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpFields;
@ -36,6 +41,8 @@ import org.eclipse.jetty.http2.client.HTTP2Client;
import org.eclipse.jetty.http2.frames.DataFrame;
import org.eclipse.jetty.http2.frames.HeadersFrame;
import org.eclipse.jetty.http2.frames.ResetFrame;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
@ -146,6 +153,31 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
}
}
@Test
public void testRequestHasHTTP2Version() throws Exception
{
start(new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
baseRequest.setHandled(true);
HttpVersion version = HttpVersion.fromString(request.getProtocol());
response.setStatus(version == HttpVersion.HTTP_2 ? HttpStatus.OK_200 : HttpStatus.INTERNAL_SERVER_ERROR_500);
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.onRequestBegin(request ->
{
if (request.getVersion() != HttpVersion.HTTP_2)
request.abort(new Exception("Not a HTTP/2 request"));
})
.send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
@Ignore
@Test
public void testExternalServer() throws Exception