twain 2.1.2.0 → 2.2.0.0
raw patch · 4 files changed
+27/−11 lines, 4 filesdep ~http2
Dependency ranges changed: http2
Files
- changelog.md +4/−0
- src/Web/Twain/Internal.hs +14/−9
- src/Web/Twain/Types.hs +7/−0
- twain.cabal +2/−2
changelog.md view
@@ -1,5 +1,9 @@ # Change Log +## 2.2.0.0 [2024-10-12]++Bump version bounds for http2 to >=5.0 && <5.4+ ## 2.1.2.0 [2023-04-10] Bump version bounds for transformers so Twain can be built with GHC 9.6.1
src/Web/Twain/Internal.hs view
@@ -1,6 +1,6 @@ module Web.Twain.Internal where -import Control.Exception (handle, throwIO)+import Control.Exception (Exception, handle, throwIO) import Control.Monad (join) import Control.Monad.Catch (throwM, try) import Control.Monad.IO.Class (liftIO)@@ -16,13 +16,15 @@ import qualified Data.Vault.Lazy as V import Data.Word (Word64) import Network.HTTP.Types (Method, hCookie, mkStatus, status204, status400, status413, status500)-import Network.HTTP2.Frame (ErrorCodeId (..), HTTP2Error (..))+import Network.HTTP2.Frame (ErrorCodeId (..)) import Network.Wai (Application, Middleware, Request (..), lazyRequestBody, queryString, requestHeaders, requestMethod, responseLBS) import Network.Wai.Parse (File, ParseRequestBodyOptions, lbsBackEnd, noLimitParseRequestBodyOptions, parseRequestBodyEx) import Network.Wai.Request (RequestSizeException (..), requestSizeCheck) import System.IO.Unsafe (unsafePerformIO) import Web.Cookie (SetCookie, parseCookiesText, renderSetCookie) import Web.Twain.Types+import Network.HTTP2.Client (HTTP2Error (..), ErrorCode(..))+import qualified Data.ByteString.Char8 as BC parsedReqKey :: V.Key ParsedRequest parsedReqKey = unsafePerformIO V.newKey@@ -105,6 +107,7 @@ setRequest $ req {vault = V.insert parsedReqKey preq' (vault req)} return json +wrapErr :: IO a -> IO a wrapErr = handle wrapMaxReqErr . handle wrapParseErr wrapMaxReqErr :: RequestSizeException -> IO a@@ -112,13 +115,15 @@ throwIO $ HttpError status413 $ "Request body size larger than " <> show max <> " bytes." -wrapParseErr :: HTTP2Error -> IO a-wrapParseErr (ConnectionError (UnknownErrorCode code) msg) = do- let msg' = unpack $ decodeUtf8 msg- throwIO $ HttpError (mkStatus (fromIntegral code) msg) msg'-wrapParseErr (ConnectionError _ msg) = do- let msg' = unpack $ decodeUtf8 msg- throwIO $ HttpError status500 msg'++wrapParseErr :: HTTP2Exception -> IO a+wrapParseErr (HTTP2Exception (ErrorCode code)) = do+ let statusCode = fromIntegral code+ statusMsg = BC.pack $ "HTTP/2 error: " ++ show code+ status = mkStatus statusCode statusMsg+ errorMsg = unpack $ decodeUtf8 statusMsg+ throwIO $ HttpError status errorMsg+ parseCookieParams :: Request -> [Param] parseCookieParams req =
src/Web/Twain/Types.hs view
@@ -14,11 +14,13 @@ import Data.Text as T import Data.Text.Encoding import qualified Data.Text.Lazy as TL+import Data.Typeable (Typeable) import Data.Word import Network.HTTP.Types (Status, status400) import Network.Wai (Middleware, Request, Response, pathInfo) import Network.Wai.Parse (File, ParseRequestBodyOptions) import Numeric.Natural+import Network.HTTP2.Client (ErrorCode(..)) -- | `ResponderM` is an Either-like monad that can "short-circuit" and return a -- response, or pass control to the next middleware. This provides convenient@@ -181,3 +183,8 @@ [x] -> Right x [] -> Left $ HttpError status400 "readEither: no parse" _ -> Left $ HttpError status400 "readEither: ambiguous parse"++data HTTP2Exception = HTTP2Exception ErrorCode+ deriving (Show, Typeable)++instance Exception HTTP2Exception
twain.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: twain-version: 2.1.2.0+version: 2.2.0.0 synopsis: Tiny web application framework for WAI. description: Twain is tiny web application framework for WAI. It provides routing, parameter parsing, and an either-like monad for composing responses. category: Web@@ -44,7 +44,7 @@ , either ==5.0.* , exceptions ==0.10.* , http-types ==0.12.*- , http2 >=1.0.0 && <3.3.0+ , http2 >=5.0 && <5.4 , text >=1.2.3 && <3 , time >=1.8 && <2 , transformers >=0.5.6 && <0.7