@@ -58,17 +58,25 @@ import Network.Socket (fdSocket)
5858#endif
5959
6060-- | Creating 'Connection' for plain HTTP based on a given socket.
61−socketConnection :: Socket -> IO Connection
62−socketConnection s = do
61+socketConnection :: Settings -> Socket -> IO Connection
62+socketConnection set s = do
6363 bufferPool <- newBufferPool
6464 writeBuf <- allocateBuffer bufferSize
6565 let sendall = Sock.sendAll s
66+ isH2 <- newIORef False -- HTTP/1.x
6667 return Connection {
6768 connSendMany = Sock.sendMany s
6869 , connSendAll = sendall
6970 , connSendFile = sendFile s writeBuf bufferSize sendall
7071#if MIN_VERSION_network(3,1,1)
71− , connClose = gracefulClose s 5000
72+ , connClose = do
73+ h2 <- readIORef isH2
74+ let tm = if h2 then settingsGracefulCloseTiemout2 set
75+ else settingsGracefulCloseTiemout1 set
76+ if tm == 0 then
77+ close s
78+ else
79+ gracefulClose s tm
7280#else
7381 , connClose = close s
7482#endif
@@ -77,6 +85,7 @@ socketConnection s = do
7785 , connRecvBuf = receiveBuf s
7886 , connWriteBuffer = writeBuf
7987 , connBufferSize = bufferSize
88+ , connHTTP2 = isH2
8089 }
8190
8291-- | Run an 'Application' on the given port.
@@ -138,7 +147,7 @@ runSettingsSocket set socket app = do
138147 setSocketCloseOnExec s
139148 -- NoDelay causes an error for AF_UNIX.
140149 setSocketOption s NoDelay 1 `E.catch` \(E.SomeException _) -> return ()
141− conn <- socketConnection s
150+ conn <- socketConnection set s
142151 return (conn, sa)
143152
144153 closeListenSocket = close socket
@@ -344,6 +353,7 @@ serveConnection conn ii th origAddr transport settings app = do
344353 let recvN = wrappedRecvN th istatus (settingsSlowlorisSize settings) rawRecvN
345354 -- fixme: origAddr
346355 checkTLS
356+ setConnHTTP2 conn True
347357 http2 conn transport ii origAddr settings recvN app
348358 else do
349359 src <- mkSource (wrappedRecv conn th istatus (settingsSlowlorisSize settings))