Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty HTTP/2 server talks with HTTP/1 client?

Hi,

On Thu, Mar 31, 2016 at 10:44 AM, John Jiang <john.sha.jiang@xxxxxxxxx> wrote:
> Hi,
> Sorry for the late reply.
>
> Please allow me to describe more clearly.
>
> 1. When my Jetty 9.3.5 server started, the below logs were shown,
> 2016-03-31 15:55:07.476:INFO:oejs.ServerConnector:main: Started
> ServerConnector@10d59286{HTTP/1.1,[http/1.1, h2c, h2c-17, h2c-16, h2c-15,
> h2c-14]}{0.0.0.0:8080}

This connector speaks HTTP/1.1 and will be able to speak HTTP/2
clear-text (h2c) when an upgrade is performed.

> 2016-03-31 15:55:08.699:INFO:oejus.SslContextFactory:main:
> x509=X509@5123a213(1,h=[sc11136070.us.oracle.com],w=[]) for
> SslContextFactory@52525845(...)
> 2016-03-31 15:55:12.725:INFO:oejs.ServerConnector:main: Started
> ServerConnector@4be242d9{SSL,[ssl, alpn, h2, h2-17, h2-16, h2-15, h2-14,
> http/1.1]}{0.0.0.0:8081}

This connector speaks SSL, it is configured with ALPN, so will be able
to speak HTTP/2 and HTTP/1.1 based on the ALPN protocol negotiated.

> 2016-03-31 15:55:12.726:INFO:oejs.Server:main: Started @23362ms
>
> I think it means that the server supports HTTP/2 with/without TLS. Right?

Correct.

> 2. I used the following test codes,
> public void testHttp() throws Exception, InterruptedException,
>         ExecutionException, TimeoutException {
>     String url = "https://localhost:8081";;
>     HttpClient client = new HttpClient(sslContextFactory); // This SSL setup
> has no problem.

You are using the HTTP/1.1 transport here, so no HTTP/2 from the client.

>     client.start();
>     HttpRequest request = (HttpRequest) client.newRequest(url);
>     System.out.println(request);
>     ContentResponse response = request.send();
>     System.out.println(response.getStatus());
>     client.stop();
> }
>
> And I got the below output:
> 2016-03-31 16:31:55.450:INFO::main: Logging initialized @522ms
> HttpRequest[GET  HTTP/1.1]@64bfbc86
> 2016-03-31 16:31:57.556:WARN:oejh.HttpParser:HttpClient@32374789-14: Illegal
> character 0x0 in state=START for buffer
> DirectByteBuffer@5684296a[p=1,l=32,c=16384,r=31]={\x00<<<\x00\x17\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01invalid_preface>>>\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}

So, the client sent a HTTP/1.1 request, and the server replied with a
HTTP/2 GOAWAY frame saying "invalid_preface".

You are not using ALPN on the client, so this tells me that you have
chosen HTTP/2 to be the default protocol on the server.

What you want to do is to tell the ALPN ConnectionFactory what is the
default protocol. In your case it should be "http/1.1".
See ALPNServerConnectionFactory.setDefaultProtocol(String).

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.


Back to the top