Skip to content

Commit

Permalink
Merge PR #1007
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Sep 24, 2024
2 parents 266f238 + 12e40c9 commit ec5e017
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
5 changes: 5 additions & 0 deletions warp-tls/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## 3.4.7

* Expose `attachConn` to use post-handshake TLS connection.
[#1007](https://github.com/yesodweb/wai/pull/1007)

## 3.4.6

* Preparing for tls v2.1
Expand Down
31 changes: 19 additions & 12 deletions warp-tls/Network/Wai/Handler/WarpTLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ module Network.Wai.Handler.WarpTLS (

-- * Exception
WarpTLSException (..),

-- * Low-level
attachConn
) where

import Control.Applicative ((<|>))
Expand Down Expand Up @@ -357,14 +360,9 @@ httpOverTls TLSSettings{..} _set s bs0 params =
ctx <- TLS.contextNew (backend recvN) params
TLS.contextHookSetLogging ctx tlsLogging
TLS.handshake ctx
h2 <- (== Just "h2") <$> TLS.getNegotiatedProtocol ctx
isH2 <- I.newIORef h2
writeBuffer <- createWriteBuffer 16384
writeBufferRef <- I.newIORef writeBuffer
-- Creating a cache for leftover input data.
tls <- getTLSinfo ctx
mysa <- getSocketName s
return (conn ctx writeBufferRef isH2 mysa, tls)
attachConn mysa ctx
wrappedRecvN recvN n = handleAny (const mempty) $ recvN n
backend recvN =
TLS.Backend
{ TLS.backendFlush = return ()
Expand All @@ -386,7 +384,20 @@ httpOverTls TLSSettings{..} _set s bs0 params =
)
throwIO
$ sendAll sock bs
conn ctx writeBufferRef isH2 mysa =

-- | Get "Connection" and "Transport" for a TLS connection that is already did the handshake.
-- @since 3.4.7
attachConn :: SockAddr -> TLS.Context -> IO (Connection, Transport)
attachConn mysa ctx = do
h2 <- (== Just "h2") <$> TLS.getNegotiatedProtocol ctx
isH2 <- I.newIORef h2
writeBuffer <- createWriteBuffer 16384
writeBufferRef <- I.newIORef writeBuffer
-- Creating a cache for leftover input data.
tls <- getTLSinfo ctx
return (conn writeBufferRef isH2, tls)
where
conn writeBufferRef isH2 =
Connection
{ connSendMany = TLS.sendData ctx . L.fromChunks
, connSendAll = sendall
Expand Down Expand Up @@ -434,10 +445,6 @@ httpOverTls TLSSettings{..} _set s bs0 params =
(const (return ()))
(TLS.bye ctx)

wrappedRecvN recvN n = handleAny handler $ recvN n
handler :: SomeException -> IO S.ByteString
handler _ = return ""

getTLSinfo :: TLS.Context -> IO Transport
getTLSinfo ctx = do
proto <- TLS.getNegotiatedProtocol ctx
Expand Down
2 changes: 1 addition & 1 deletion warp-tls/warp-tls.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: warp-tls
Version: 3.4.6
Version: 3.4.7
Synopsis: HTTP over TLS support for Warp via the TLS package
License: MIT
License-file: LICENSE
Expand Down
5 changes: 5 additions & 0 deletions warp/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog for warp

## 3.4.2

* serveConnection is re-exported from the Internal module.
[#1007](https://github.com/yesodweb/wai/pull/1007)

## 3.4.1

* Using time-manager v0.1.0, and auto-update v0.2.0.
Expand Down
1 change: 1 addition & 0 deletions warp/Network/Wai/Handler/Warp/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module Network.Wai.Handler.Warp.Internal (
-- * Misc
http2server,
withII,
serveConnection,
pReadMaker,
) where

Expand Down
2 changes: 1 addition & 1 deletion warp/warp.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: >=1.10
name: warp
version: 3.4.1
version: 3.4.2
license: MIT
license-file: LICENSE
maintainer: [email protected]
Expand Down

0 comments on commit ec5e017

Please sign in to comment.