Skip to content

Commit 9c93efd

Browse files
committed
Add TestAlpnFallback
1 parent 00479a6 commit 9c93efd

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

test/org/apache/tomcat/util/net/TesterSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static boolean isTlsv13Available() {
128128
}
129129

130130
public static void initSsl(Tomcat tomcat) {
131-
// By default, use JSSE JSSE trust
131+
// By default, use JSSE trust
132132
initSsl(tomcat, false);
133133
}
134134

0 commit comments

Comments
 (0)