ngx-export-tools-extra 0.4.0.0 → 0.4.1.0
raw patch · 4 files changed
+44/−24 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ NgxExport.Tools.EDE: renderEDETemplateFromFreeValue :: ByteString -> IO ByteString
Files
- Changelog.md +5/−0
- NgxExport/Tools/EDE.hs +33/−16
- NgxExport/Tools/Subrequest.hs +5/−7
- ngx-export-tools-extra.cabal +1/−1
Changelog.md view
@@ -1,3 +1,8 @@+### 0.4.1.0++- Handler *renderEDETemplateFromFreeValue* was moved from the example to the+ module.+ ### 0.4.0.0 - Implemented adjustable response timeouts.
NgxExport/Tools/EDE.hs view
@@ -21,6 +21,7 @@ -- $renderingEDETemplates renderEDETemplate ,renderEDETemplateWith+ ,renderEDETemplateFromFreeValue ) where import NgxExport@@ -48,6 +49,7 @@ import Data.Aeson (encode, decode, Value (String)) import Network.HTTP.Types.URI (urlEncode) import Control.Exception (Exception, throwIO)+import Control.Arrow import System.IO.Unsafe -- $renderingEDETemplates@@ -55,15 +57,20 @@ -- This module allows for complex parsing of JSON objects with [EDE templating -- language](http://hackage.haskell.org/package/ede/docs/Text-EDE.html). In -- terms of module "NgxExport.Tools", it exports a /single-shot/ service--- __/compileEDETemplates/__ to configure the list of templates parameterized--- by a simple key, and an asynchronous variable handler __/renderEDETemplate/__--- for parsing POSTed JSON objects and substitution of extracted data in the--- provided EDE template.+-- __/compileEDETemplates/__ to configure a list of templates parameterized by+-- a simple key, and two variable handlers __/renderEDETemplate/__ and+-- __/renderEDETemplateFromFreeValue/__ for parsing JSON objects and+-- substitution of extracted data into provided EDE templates. The former+-- handler is /asynchronous/ and suitable for parsing JSON objects POSTed in a+-- request body, while the latter is /synchronous/ and can parse JSON objects+-- contained in Nginx variables. -- -- Below is a simple example. -- -- ==== File /test_tools_extra_ede.hs/ -- @+-- {-\# OPTIONS_GHC -Wno-unused-imports \#-}+-- -- {-\# LANGUAGE TemplateHaskell \#-} -- -- module TestToolsExtraEDE where@@ -72,26 +79,21 @@ -- import NgxExport.Tools.EDE -- -- import Data.ByteString (ByteString)--- import qualified Data.ByteString.Char8 as C8 -- import qualified Data.ByteString.Lazy as L -- import qualified Network.HTTP.Types.URI as URI--- import Control.Arrow ----- renderEDETemplateFromFreeValue :: ByteString -> IO L.ByteString--- __/renderEDETemplateFromFreeValue/__ = uncurry (flip renderEDETemplate) .--- second (L.fromStrict . C8.tail) . C8.break (== \'|\')------ 'ngxExportIOYY' \'renderEDETemplateFromFreeValue--- -- urlDecode :: ByteString -> L.ByteString -- urlDecode = L.fromStrict . URI.urlDecode False -- -- 'ngxExportYY' \'urlDecode -- @ ----- Besides the two handlers imported from the EDE module, two additional--- handlers were defined here: /renderEDETemplateFromFreeValue/ and /urlDecode/.--- We are going to use them for parsing JSON values from HTTP cookies.+-- We are going to use /urlDecode/ to decode JSON values contained in HTTP+-- cookies. Notice that we are not using any Haskell declarations from module+-- /NgxExport.Tools.EDE/ while still need to import this to access the three+-- handlers from the Nginx configuration. This situation is quite valid though+-- not usual to /ghc/, and to make it keep silence, pragma+-- /OPTIONS_GHC -Wno-unused-imports/ was added on the top of the file. -- -- ==== File /nginx.conf/ -- @@@ -175,7 +177,9 @@ -- -- So, basically, we used /renderEDETemplate/ to decompose POSTed JSON objects -- and then /rewrite/ requests to other locations where extracted fields were--- encoded inside the location's URL path.+-- encoded inside the location's URL path. Handler+-- /renderEDETemplateFromFreeValue/ in /location \/cookie/ does the same but+-- reads JSON objects from HTTP cookie /user/. -- -- ==== A simple test --@@ -277,4 +281,17 @@ #endif ngxExportAsyncOnReqBody 'renderEDETemplate++-- | Renders an EDE template from a JSON object.+--+-- This is the core function of the /renderEDETemplateFromFreeValue/ handler.+-- Accepts a JSON object attached after the search key and a vertical bar such+-- as /key|$hs_json/.+renderEDETemplateFromFreeValue+ :: ByteString -- ^ Key to find the EDE template, and JSON object+ -> IO L.ByteString+renderEDETemplateFromFreeValue = uncurry (flip renderEDETemplate) .+ second (L.fromStrict . C8.tail) . C8.break (== '|')++ngxExportIOYY 'renderEDETemplateFromFreeValue
NgxExport/Tools/Subrequest.hs view
@@ -438,7 +438,7 @@ -- argument /$arg_p/. Skipping this makes URI look unparsable -- (/http:\/\/127.0.0.1:\//) which leads to the error. ----- > curl -D- 'http://localhost:8010/full/?a=Value&p=8020'+-- > $ curl -D- 'http://localhost:8010/full/?a=Value&p=8020' -- > HTTP/1.1 200 OK -- > Server: nginx/1.17.9 -- > Date: Sat, 04 Apr 2020 12:52:03 GMT@@ -455,7 +455,7 @@ -- -- Let's try another port. ----- > curl -D- 'http://localhost:8010/full/?a=Value&p=8021'+-- > $ curl -D- 'http://localhost:8010/full/?a=Value&p=8021' -- > HTTP/1.1 502 Bad Gateway -- > Server: nginx/1.17.9 -- > Date: Sat, 04 Apr 2020 12:56:02 GMT@@ -516,11 +516,9 @@ -- | Extracts a specified header from an encoded response. -- -- Must be used to extract response data encoded by 'makeSubrequestFull' and--- 'makeSubrequestFullWithRead'.------ Expects that the encoded response data is attached after the name of the--- header and a vertical bar such as /Header-Name|$hs_body/. The lookup of the--- header name is case-insensitive.+-- 'makeSubrequestFullWithRead'. Expects that the encoded response data is+-- attached after the name of the header and a vertical bar such as+-- /Header-Name|$hs_body/. The lookup of the header name is case-insensitive. -- -- Exported on the Nginx level by a handler of the same name. extractHeaderFromFullResponse :: ByteString -> L.ByteString
ngx-export-tools-extra.cabal view
@@ -1,5 +1,5 @@ name: ngx-export-tools-extra-version: 0.4.0.0+version: 0.4.1.0 synopsis: More extra tools for Nginx haskell module description: More extra tools for <https://github.com/lyokha/nginx-haskell-module Nginx haskell module>.