on master help sign in
Add an option to disable HTTP2

Fixes #450

commitfeed7f72f0764be3cd10a9b58c700d7448c69560 authorDylan Simon <dylan@dylex.net> dateSun 18 Oct 2015, 23:31 (11 years ago) parent167f354
4 files changed+16−2
warp-tls/Network/Wai/Handler/WarpTLS.hs+3−1 warp/Network/Wai/Handler/Warp.hs+7 warp/Network/Wai/Handler/Warp/Run.hs+1−1 warp/Network/Wai/Handler/Warp/Settings.hs+5
warp-tls/Network/Wai/Handler/WarpTLS.hs+3−1
@@ -44,6 +44,7 @@ module Network.Wai.Handler.WarpTLS (
4444#if __GLASGOW_HASKELL__ < 709
4545import Control.Applicative ((<$>))
4646#endif
47+import Control.Applicative ((<|>))
4748import Control.Exception (Exception, throwIO, bracket, finally, handle, fromException, try, IOException, onException, SomeException(..))
4849import qualified Control.Exception as E
4950import Control.Monad (void)
@@ -279,7 +280,8 @@ runServeTLSSocket' tlsset@TLSSettings{..} set credential sock serve =
279280 }
280281 -- Adding alpn to user's tlsServerHooks.
281282 hooks = tlsServerHooks {
282− TLS.onALPNClientSuggest = Just alpn
283+ TLS.onALPNClientSuggest = TLS.onALPNClientSuggest tlsServerHooks <|>
284+ (if settingsHTTP2Enabled set then Just alpn else Nothing)
283285 }
284286 shared = def {
285287 TLS.sharedCredentials = TLS.Credentials [credential]
warp/Network/Wai/Handler/Warp.hs+7
@@ -76,6 +76,7 @@ module Network.Wai.Handler.Warp (
7676 , setProxyProtocolRequired
7777 , setProxyProtocolOptional
7878 , setSlowlorisSize
79+ , setHTTP2Disabled
7980 -- ** Getters
8081 , getPort
8182 , getHost
@@ -356,6 +357,12 @@ setProxyProtocolOptional y = y { settingsProxyProtocol = ProxyProtocolOptional }
356357setSlowlorisSize :: Int -> Settings -> Settings
357358setSlowlorisSize x y = y { settingsSlowlorisSize = x }
358359
360+-- | Disable HTTP2.
361+--
362+-- Since 3.1.7
363+setHTTP2Disabled :: Settings -> Settings
364+setHTTP2Disabled y = y { settingsHTTP2Enabled = False }
365+
359366-- | Explicitly pause the slowloris timeout.
360367--
361368-- This is useful for cases where you partially consume a request body. For
warp/Network/Wai/Handler/Warp/Run.hs+1−1
@@ -387,7 +387,7 @@ serveHTTP2 app2 app conn ii origAddr transport settings = do
387387 return (True, bs0)
388388 else
389389 return (False, bs0)
390− if h2 then do
390+ if settingsHTTP2Enabled settings && h2 then do
391391 recvN <- makeReceiveN bs (connRecv conn) (connRecvBuf conn)
392392 -- fixme: origAddr
393393 http2 conn ii origAddr transport settings recvN app2
warp/Network/Wai/Handler/Warp/Settings.hs+5
@@ -92,6 +92,10 @@ data Settings = Settings
9292 -- ^ Size of bytes read to prevent Slowloris protection. Default value: 2048
9393 --
9494 -- Since 3.1.2.
95+ , settingsHTTP2Enabled :: Bool
96+ -- ^ Whether to enable HTTP2 ALPN/upgrades. Default: True
97+ --
98+ -- Since 3.1.7.
9599 }
96100
97101-- | Specify usage of the PROXY protocol.
@@ -123,6 +127,7 @@ defaultSettings = Settings
123127 , settingsMaximumBodyFlush = Just 8192
124128 , settingsProxyProtocol = ProxyProtocolNone
125129 , settingsSlowlorisSize = 2048
130+ , settingsHTTP2Enabled = True
126131 }
127132
128133-- | Apply the logic provided by 'defaultOnException' to determine if an