From 1553aabb2fbfffee84b1837e150c124987ad4b34 Mon Sep 17 00:00:00 2001 From: ejona Date: Thu, 6 Nov 2014 14:32:05 -0800 Subject: [PATCH] Advertise h2-15 in ALPN negotiation. We continue to support h2-14 to prevent having a flag-day. Flag-day is unnecessary since h2-15 is pretty much the same as h2-14. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=79369997 --- .../stubby/transport/netty/Http2Negotiator.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/netty/src/main/java/com/google/net/stubby/transport/netty/Http2Negotiator.java b/netty/src/main/java/com/google/net/stubby/transport/netty/Http2Negotiator.java index f3b02ecb80..7d9bdea877 100644 --- a/netty/src/main/java/com/google/net/stubby/transport/netty/Http2Negotiator.java +++ b/netty/src/main/java/com/google/net/stubby/transport/netty/Http2Negotiator.java @@ -26,6 +26,8 @@ import io.netty.util.concurrent.GenericFutureListener; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -37,8 +39,10 @@ import javax.net.ssl.SSLEngine; * endpoint. */ public class Http2Negotiator { - public static final String HTTP_VERSION_NAME = - Http2OrHttpChooser.SelectedProtocol.HTTP_2.protocolName(); + private static final List SUPPORTED_PROTOCOLS = Collections.unmodifiableList( + Arrays.asList( + Http2OrHttpChooser.SelectedProtocol.HTTP_2.protocolName(), + "h2-15")); // Prefer ALPN to NPN so try it first. private static final String[] JETTY_TLS_NEGOTIATION_IMPL = @@ -278,18 +282,19 @@ public class Http2Negotiator { // all removeMethod.invoke(null, engine); protocolNegotiated.setException(new RuntimeException( - "ALPN/NPN protocol " + HTTP_VERSION_NAME + " not supported by endpoint")); + "Endpoint does not support any of " + SUPPORTED_PROTOCOLS + + " in ALPN/NPN negotiation")); return null; } if ("protocols".equals(methodName)) { // ALPN client, NPN server - return ImmutableList.of(HTTP_VERSION_NAME); + return SUPPORTED_PROTOCOLS; } if ("selected".equals(methodName) || "protocolSelected".equals(methodName)) { // ALPN client, NPN server removeMethod.invoke(null, engine); String protocol = (String) args[0]; - if (!HTTP_VERSION_NAME.equals(protocol)) { + if (!SUPPORTED_PROTOCOLS.contains(protocol)) { RuntimeException e = new RuntimeException( "Unsupported protocol selected via ALPN/NPN: " + protocol); protocolNegotiated.setException(e); @@ -310,7 +315,7 @@ public class Http2Negotiator { @SuppressWarnings("unchecked") List names = (List) args[0]; for (String name : names) { - if (name.startsWith(HTTP_VERSION_NAME)) { + if (SUPPORTED_PROTOCOLS.contains(name)) { protocolNegotiated.set(null); return name; }