|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.tomcat.util.net; |
| 19 | + |
| 20 | +import org.junit.Assert; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +import org.apache.catalina.Context; |
| 24 | +import org.apache.catalina.startup.Tomcat; |
| 25 | +import org.apache.coyote.http2.Http2TestBase; |
| 26 | +import org.apache.tomcat.util.buf.ByteChunk; |
| 27 | + |
| 28 | +public class TestAlpnFallback extends Http2TestBase { |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testAlpnFallbackToHttp11() throws Exception { |
| 32 | + TesterSupport.configureClientSsl(); |
| 33 | + //There's no ALPN negotiation without TLS |
| 34 | + enableHttp2(true); |
| 35 | + |
| 36 | + Tomcat tomcat = getTomcatInstance(); |
| 37 | + |
| 38 | + Context ctx = getProgrammaticRootContext(); |
| 39 | + Tomcat.addServlet(ctx, "snoop", new SnoopServlet()); |
| 40 | + ctx.addServletMappingDecoded("/", "snoop"); |
| 41 | + |
| 42 | + tomcat.start(); |
| 43 | + |
| 44 | + // HttpURLConnection does not support ALPN, so this request will connect over TLS without negotiating h2. |
| 45 | + // The connector must fall back to HTTP/1.1 rather than dropping the connection. |
| 46 | + ByteChunk res = new ByteChunk(); |
| 47 | + getUrl("https://localhost:" + getPort() + "/", res, null); |
| 48 | + RequestDescriptor requestDesc = SnoopResult.parse(res.toString()); |
| 49 | + Assert.assertEquals("HTTP/1.1", requestDesc.getRequestInfo("REQUEST-PROTOCOL")); |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments