From cd69ed20c3de4cd8f79737303bd9af371de3391e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 26 Apr 2014 19:36:35 +0900 Subject: [PATCH] nghttpx: Select SPDY protocol in ALPN --- src/shrpx_ssl.cc | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index a12c7f27..fc1fc23b 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -41,6 +41,10 @@ #include +#ifdef HAVE_SPDYLAY +#include +#endif // HAVE_SPDYLAY + #include "shrpx_log.h" #include "shrpx_client_handler.h" #include "shrpx_config.h" @@ -158,11 +162,33 @@ int alpn_select_proto_cb(SSL* ssl, const unsigned char *in, unsigned int inlen, void *arg) { - if(nghttp2_select_next_protocol - (const_cast(out), outlen, in, inlen) == -1) { - return SSL_TLSEXT_ERR_NOACK; + int rv; + + rv = nghttp2_select_next_protocol + (const_cast(out), outlen, in, inlen); + + if(rv == 1) { + // HTTP/2 was selected + return SSL_TLSEXT_ERR_OK; } - return SSL_TLSEXT_ERR_OK; + +#ifdef HAVE_SPDYLAY + rv = spdylay_select_next_protocol + (const_cast(out), outlen, in, inlen); + + if(rv > 0) { + // SPDY was selected + return SSL_TLSEXT_ERR_OK; + } +#endif // HAVE_SPDYLAY + + if(rv == -1) { + // No selection was made + return SSL_TLSEXT_ERR_OK; + } + + // We selected http/1.1 + return SSL_TLSEXT_ERR_NOACK; } } // namespace #endif // OPENSSL_VERSION_NUMBER >= 0x10002000L