packages feed

wai-handler-hal 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+45/−18 lines, 3 filesdep ~text

Dependency ranges changed: text

Files

CHANGELOG.md view
@@ -1,5 +1,12 @@ # Revision history for wai-handler-hal +## 0.1.1.0 -- 2021-10-14++* When API Gateway sends nonsense IPs during a test invocation, sub in+  `127.0.0.1` instead of exploding.+  [#3](https://github.com/bellroy/wai-handler-hal/issues/3)+* Removed debug `print`s left in by mistake.+ ## 0.1.0.0 -- 2021-04-15  * First version. Released on an unsuspecting world.
src/Network/Wai/Handler/Hal.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TupleSections #-}+{-# LANGUAGE TypeApplications #-} {-# OPTIONS_GHC -Wno-deprecations #-}  -- |@@ -44,6 +45,7 @@   ( RequestContext (..),   ) import qualified AWS.Lambda.Events.ApiGateway.ProxyResponse as HalResponse+import Control.Exception (IOException, tryJust) import Control.Monad.IO.Class (MonadIO (..)) import Data.ByteString (ByteString) import qualified Data.ByteString as B@@ -83,7 +85,14 @@ import qualified Network.Socket as NS import qualified Network.Wai as Wai import qualified Network.Wai.Internal as Wai-import System.IO (IOMode (..), SeekMode (..), hSeek, withFile)+import System.IO+  ( IOMode (..),+    SeekMode (..),+    hPutStrLn,+    hSeek,+    stderr,+    withFile,+  )  -- | Convert a WAI 'Wai.Application' into a function that can -- be run by hal's 'AWS.Lambda.Runtime.mRuntime'. This is the simplest@@ -175,9 +184,23 @@           . HalRequest.sourceIp           . HalRequest.identity           $ HalRequest.requestContext req-  print $ HalRequest.path req-  print pathSegments-  sourceAddr : _ <- NS.getAddrInfo (Just hints) (Just sourceIp) (Just $ show port)+  -- Test invokes from the API Gateway console pass a "sourceIp" field+  -- of "test-invoke-source-ip". If the getAddrInfo call fails, just+  -- assume localhost.+  sourceHost <-+    tryJust+      (Just @IOException)+      (NS.getAddrInfo (Just hints) (Just sourceIp) (Just $ show port))+      >>= \case+        Right (s : _) -> pure $ NS.addrAddress s+        _ -> do+          hPutStrLn stderr $+            mconcat+              [ "Cannot convert sourceIp ",+                show sourceIp,+                " to address; assuming 127.0.0.1"+              ]+          pure . NS.SockAddrInet port $ NS.tupleToHostAddress (127, 0, 0, 1)   body <- returnChunks $ HalRequest.body req   let waiReq =         Wai.Request@@ -198,7 +221,7 @@                 . H.toList                 $ HalRequest.multiValueHeaders req,             Wai.isSecure = True,-            Wai.remoteHost = NS.addrAddress sourceAddr,+            Wai.remoteHost = sourceHost,             Wai.pathInfo = pathSegments,             Wai.queryString = query,             Wai.requestBody = body,@@ -210,7 +233,6 @@             Wai.requestHeaderReferer = getHeader hReferer req,             Wai.requestHeaderUserAgent = getHeader hUserAgent req           }-  print waiReq   pure waiReq  -- | Unpack a lazy 'BL.ByteString' into its chunks, and return an IO
wai-handler-hal.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.2 name:               wai-handler-hal-version:            0.1.0.0+version:            0.1.1.0 synopsis:           Wrap WAI applications to run on AWS Lambda description:   This library provides a function 'Network.Wai.Handler.Hal.run' to@@ -21,9 +21,7 @@ copyright:          Copyright (C) 2021 Bellroy Pty Ltd category:           AWS, Cloud build-type:         Simple-extra-source-files:-  CHANGELOG.md-+extra-source-files: CHANGELOG.md tested-with:        GHC ==8.6.5 || ==8.8.4 || ==8.10.4  common opts@@ -37,17 +35,17 @@  common deps   build-depends:-    , base                  >=4.12    && <4.15-    , base64-bytestring     ^>=1.1.0.0-    , bytestring            ^>=0.10.8-    , case-insensitive      ^>=1.2.1.0+    , base                  >=4.12     && <4.16+    , base64-bytestring     >=1.0.0.0  && <1.3+    , bytestring            >=0.10.8   && <0.12+    , case-insensitive      ^>=1.2.0.0     , hal                   ^>=0.4.7     , http-types            ^>=0.12.3-    , network               ^>=3.1.1.1+    , network               >=2.8.0.0  && <3.2     , text                  ^>=1.2.3-    , unordered-containers  ^>=0.2.13-    , vault                 ^>=0.3.1.5-    , wai                   ^>=3.2.3+    , unordered-containers  ^>=0.2.10.0+    , vault                 ^>=0.3.1.0+    , wai                   ^>=3.2.2  library   import:          opts, deps