wai-handler-hal 0.1.1.0 → 0.1.2.0
raw patch · 8 files changed
+224/−7 lines, 8 filesdep +aesondep +pretty-simpledep +tastydep ~basedep ~haldep ~textPVP ok
version bump matches the API change (PVP)
Dependencies added: aeson, pretty-simple, tasty, tasty-golden, wai-handler-hal
Dependency ranges changed: base, hal, text
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- README.md +19/−0
- src/Network/Wai/Handler/Hal.hs +1/−1
- test/Main.hs +1/−0
- test/Network/Wai/Handler/HalTest.hs +21/−0
- test/data/ProxyRequest.json +89/−0
- test/golden/WaiRequest.txt +62/−0
- wai-handler-hal.cabal +27/−6
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for wai-handler-hal +## 0.1.2.0 -- 2022-06-03++* Fix construction of `rawPathInfo`.+ ## 0.1.1.0 -- 2021-10-14 * When API Gateway sends nonsense IPs during a test invocation, sub in
+ README.md view
@@ -0,0 +1,19 @@+# wai-handler-hal++[](https://github.com/bellroy/wai-handler-hal/actions/workflows/haskell-ci.yml)++This library lets you run `wai` `Application`s on AWS Lambda, which+means you can now use mature web frameworks like+[`servant`](https://hackage.haskell.org/package/servant).++The main entry point is `Network.Wai.Handler.Hal.run`, which wraps an+`Application` and returns a function that can be passed to `hal`'s+`AWS.Lambda.Runtime.mRuntime`.++**NOTE:** The function returned by `Network.Wai.Handler.Hal.run` is+only for [Lambda Proxy+Integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html)+of AWS API Gateway **REST APIs** (`AWS::ApiGateway::RestApi` in+CloudFormation). If you try to use such a Lambda with an API Gateway+**HTTP API** (`AWS::ApiGatewayV2::Api` in CloudFormation), it will+return 500s.
src/Network/Wai/Handler/Hal.hs view
@@ -209,7 +209,7 @@ Wai.rawPathInfo = BL.toStrict . Builder.toLazyByteString- $ encodePath pathSegments query,+ $ encodePath pathSegments [], Wai.rawQueryString = case query of [] -> "" _ -> renderQuery True query,
+ test/Main.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF tasty-discover #-}
+ test/Network/Wai/Handler/HalTest.hs view
@@ -0,0 +1,21 @@+{-# LANGUAGE ScopedTypeVariables #-}++module Network.Wai.Handler.HalTest where++import AWS.Lambda.Events.ApiGateway.ProxyRequest+import Data.Aeson (eitherDecodeFileStrict')+import qualified Data.Text.Lazy.Encoding as T+import Data.Void (Void)+import Network.Wai.Handler.Hal+import Test.Tasty+import Test.Tasty.Golden+import Text.Pretty.Simple++test_ConvertProxyRequest :: TestTree+test_ConvertProxyRequest =+ goldenVsString "API Gateway Proxy Request" "test/golden/WaiRequest.txt" $ do+ proxyRequest :: ProxyRequest Void <-+ eitherDecodeFileStrict' "test/data/ProxyRequest.json"+ >>= either fail pure+ waiRequest <- toWaiRequest mempty 443 proxyRequest+ pure . T.encodeUtf8 $ pShowNoColor waiRequest
+ test/data/ProxyRequest.json view
@@ -0,0 +1,89 @@+{+ "resource": "/{proxy+}",+ "path": "/foo/bar/baz",+ "httpMethod": "GET",+ "headers": {+ "accept": "application/json",+ "Host": "ffffffffff.execute-api.us-east-1.amazonaws.com",+ "User-Agent": "curl/7.83.1",+ "X-Amzn-Trace-Id": "Root=1-11111111-111111111111111111111111",+ "X-Forwarded-For": "123.123.123.123",+ "X-Forwarded-Port": "443",+ "X-Forwarded-Proto": "https"+ },+ "multiValueHeaders": {+ "accept": [+ "application/json"+ ],+ "Host": [+ "ffffffffff.execute-api.us-east-1.amazonaws.com"+ ],+ "User-Agent": [+ "curl/7.83.1"+ ],+ "X-Amzn-Trace-Id": [+ "Root=1-11111111-111111111111111111111111"+ ],+ "X-Forwarded-For": [+ "123.123.123.123"+ ],+ "X-Forwarded-Port": [+ "443"+ ],+ "X-Forwarded-Proto": [+ "https"+ ]+ },+ "queryStringParameters": {+ "MaxResultsPerPage": "100",+ "PostedAfter": "2022-05-31T22:16:43Z",+ "PostedBefore": "2022-05-31T23:16:43Z"+ },+ "multiValueQueryStringParameters": {+ "MaxResultsPerPage": [+ "100"+ ],+ "PostedAfter": [+ "2022-05-31T22:16:43Z"+ ],+ "PostedBefore": [+ "2022-05-31T23:16:43Z"+ ]+ },+ "pathParameters": {+ "proxy": "foo/bar/baz"+ },+ "stageVariables": null,+ "requestContext": {+ "resourceId": "ffffff",+ "resourcePath": "/{proxy+}",+ "httpMethod": "GET",+ "extendedRequestId": "AAAAAAAAAAAAAAA=",+ "requestTime": "02/Jun/2022:08:01:41 +0000",+ "path": "/test/foo/bar/baz",+ "accountId": "123456789012",+ "protocol": "HTTP/1.1",+ "stage": "test",+ "domainPrefix": "ffffffffff",+ "requestTimeEpoch": 1654156901017,+ "requestId": "0bb0f1d1-5063-45ab-a0dc-4d10279eb9e1",+ "identity": {+ "cognitoIdentityPoolId": null,+ "accountId": null,+ "cognitoIdentityId": null,+ "caller": null,+ "sourceIp": "123.123.123.123",+ "principalOrgId": null,+ "accessKey": null,+ "cognitoAuthenticationType": null,+ "cognitoAuthenticationProvider": null,+ "userArn": null,+ "userAgent": "curl/7.83.1",+ "user": null+ },+ "domainName": "ffffffffff.execute-api.us-east-1.amazonaws.com",+ "apiId": "ffffffffff"+ },+ "body": null,+ "isBase64Encoded": false+}
+ test/golden/WaiRequest.txt view
@@ -0,0 +1,62 @@+Request+ { requestMethod = "GET"+ , httpVersion = HTTP/1.1+ , rawPathInfo = "/foo/bar/baz"+ , rawQueryString = "?PostedBefore=2022-05-31T23%3A16%3A43Z&MaxResultsPerPage=100&PostedAfter=2022-05-31T22%3A16%3A43Z"+ , requestHeaders =+ [+ ( "X-Forwarded-Port"+ , "443"+ )+ ,+ ( "Host"+ , "ffffffffff.execute-api.us-east-1.amazonaws.com"+ )+ ,+ ( "accept"+ , "application/json"+ )+ ,+ ( "X-Forwarded-Proto"+ , "https"+ )+ ,+ ( "User-Agent"+ , "curl/7.83.1"+ )+ ,+ ( "X-Amzn-Trace-Id"+ , "Root=1-11111111-111111111111111111111111"+ )+ ,+ ( "X-Forwarded-For"+ , "123.123.123.123"+ )+ ]+ , isSecure = True+ , remoteHost = 123.123.123.123:443+ , pathInfo =+ [ "foo"+ , "bar"+ , "baz"+ ]+ , queryString =+ [+ ( "PostedBefore"+ , Just "2022-05-31T23:16:43Z"+ )+ ,+ ( "MaxResultsPerPage"+ , Just "100"+ )+ ,+ ( "PostedAfter"+ , Just "2022-05-31T22:16:43Z"+ )+ ]+ , requestBody = <IO ByteString>+ , vault = <Vault>+ , requestBodyLength = KnownLength 0+ , requestHeaderHost = Just "ffffffffff.execute-api.us-east-1.amazonaws.com"+ , requestHeaderRange = Nothing+ }
wai-handler-hal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: wai-handler-hal-version: 0.1.1.0+version: 0.1.2.0 synopsis: Wrap WAI applications to run on AWS Lambda description: This library provides a function 'Network.Wai.Handler.Hal.run' to@@ -21,8 +21,13 @@ copyright: Copyright (C) 2021 Bellroy Pty Ltd category: AWS, Cloud build-type: Simple-extra-source-files: CHANGELOG.md-tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.4+extra-source-files:+ CHANGELOG.md+ README.md+ test/data/ProxyRequest.json+ test/golden/WaiRequest.txt+tested-with:+ GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.2 common opts default-language: Haskell2010@@ -35,14 +40,14 @@ common deps build-depends:- , base >=4.12 && <4.16+ , base >=4.12 && <4.17 , base64-bytestring >=1.0.0.0 && <1.3 , bytestring >=0.10.8 && <0.12 , case-insensitive ^>=1.2.0.0- , hal ^>=0.4.7+ , hal >=0.4.7 && <0.4.11 || >=1.0.0 && <1.1 , http-types ^>=0.12.3 , network >=2.8.0.0 && <3.2- , text ^>=1.2.3+ , text ^>=1.2.3 || ^>=2.0 , unordered-containers ^>=0.2.10.0 , vault ^>=0.3.1.0 , wai ^>=3.2.2@@ -51,6 +56,22 @@ import: opts, deps exposed-modules: Network.Wai.Handler.Hal hs-source-dirs: src++test-suite wai-handler-hal-tests+ import: deps, opts+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Main.hs+ ghc-options: -threaded+ other-modules: Network.Wai.Handler.HalTest+ build-tool-depends: tasty-discover:tasty-discover ^>=4.2.2+ build-depends:+ , aeson ^>=1.5.6.0 || ^>=2.0+ , pretty-simple ^>=4.1.0.0+ , tasty >=1.3 && <1.5+ , tasty-golden ^>=2.3+ , text+ , wai-handler-hal source-repository head type: git