ngx-export-tools-extra 1.2.8 → 1.2.8.1
raw patch · 4 files changed
+79/−12 lines, 4 filesdep ~ngx-export-toolsPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: ngx-export-tools
API changes (from Hackage documentation)
Files
- Changelog.md +7/−0
- NgxExport/Tools/PCRE.hs +2/−2
- NgxExport/Tools/ServiceHookAdaptor.hs +68/−8
- ngx-export-tools-extra.cabal +2/−2
Changelog.md view
@@ -1,3 +1,10 @@+### 1.2.8.1++- Module *NgxExport.Tools.PCRE*.+ + Use *voidServer* from *ngx-export-tools ≥ 1.2.3*.+- Module *NgxExport.Tools.ServiceHookAdaptor*.+ + The test example was improved and extended.+ ### 1.2.8 - Module *NgxExport.Tools.Subrequest*.
NgxExport/Tools/PCRE.hs view
@@ -3,7 +3,7 @@ ----------------------------------------------------------------------------- -- | -- Module : NgxExport.Tools.PCRE--- Copyright : (c) Alexey Radkov 2021-2023+-- Copyright : (c) Alexey Radkov 2021-2024 -- License : BSD-style -- -- Maintainer : alexey.radkov@gmail.com@@ -161,7 +161,7 @@ {-# NOINLINE regexes #-} declareRegexes :: InputRegexes -> NgxExportService-declareRegexes = ignitionService $ voidHandler' $ return ()+declareRegexes = voidService ngxExportSimpleServiceTyped 'declareRegexes ''InputRegexes SingleShotService
NgxExport/Tools/ServiceHookAdaptor.hs view
@@ -3,7 +3,7 @@ ----------------------------------------------------------------------------- -- | -- Module : NgxExport.Tools.ServiceHookAdaptor--- Copyright : (c) Alexey Radkov 2021-2023+-- Copyright : (c) Alexey Radkov 2021-2024 -- License : BSD-style -- -- Maintainer : alexey.radkov@gmail.com@@ -51,8 +51,16 @@ -- import qualified Data.ByteString as B -- import qualified Data.ByteString.Lazy as L -- import Data.IORef+-- import Control.Monad+-- import Control.Exception -- import System.IO.Unsafe --+-- data SecretWordUnset = SecretWordUnset+--+-- instance Exception SecretWordUnset+-- instance Show SecretWordUnset where+-- show = const \"unset\"+-- -- secretWord :: IORef ByteString -- secretWord = unsafePerformIO $ newIORef "" -- {-\# NOINLINE secretWord \#-}@@ -60,11 +68,10 @@ -- testSecretWord :: ByteString -> IO L.ByteString -- __/testSecretWord/__ v = do -- s <- readIORef secretWord--- return $ if B.null s--- then \"null\"--- else if v == s--- then \"set\"--- else \"unset\"+-- when (B.null s) $ throwIO SecretWordUnset+-- return $ if v == s+-- then \"success\"+-- else \"\" -- 'NgxExport.ngxExportIOYY' 'testSecretWord -- -- changeSecretWord :: ByteString -> IO L.ByteString@@ -110,13 +117,13 @@ -- location \/ { -- haskell_run __/testSecretWord/__ $hs_secret_word $arg_s; ----- if ($hs_secret_word = null) {+-- if ($hs_secret_word = unset) { -- echo_status 503; -- echo \"Try later! The service is not ready!\"; -- break; -- } ----- if ($hs_secret_word = set) {+-- if ($hs_secret_word = success) { -- echo_status 200; -- echo \"Congrats! You know the secret word!\"; -- break;@@ -181,6 +188,59 @@ -- -- Our secret is still intact! This is because service hooks manage new worker -- processes so well as those that were running when a hook was triggered.+--+-- Note, however, that the order of service hooks execution in a restarted+-- worker process is not well-defined which means that hooks that affect the+-- same data should be avoided. For example, we could declare another service+-- hook to reset the secret word.+--+-- ==== File /test_tools_extra_servicehookadaptor.hs/: reset the secret word+-- @+-- resetSecretWord :: ByteString -> IO L.ByteString+-- __/resetSecretWord/__ = const $ do+-- writeIORef secretWord \"\"+-- return \"The secret word was reset\"+-- 'NgxExport.ngxExportServiceHook' \'resetSecretWord+-- @+--+-- ==== File /nginx.conf/: new location /\/reset_sw/ in server /main/+-- @+-- location \/reset_sw {+-- allow 127.0.0.1;+-- deny all;+--+-- haskell_service_hook __/resetSecretWord/__ $hs_hook_adaptor;+-- }+-- @+--+-- Both /changeSecretWord/ and /resetSecretWord/ alter the /secretWord/ storage.+-- The order of their execution in a restarted worker process may differ from+-- the order they had happened before the new worker started, and therefore the+-- state of /secretWord/ can get altered in the new worker.+--+-- To fix this issue in this example, get rid of hook /resetSecretWord/ and use+-- directive /rewrite/ to process the reset request in location /\/change_sw/.+--+-- @+-- location \/reset_sw {+-- allow 127.0.0.1;+-- deny all;+--+-- rewrite ^ \/change_sw last;+-- }+-- @+--+-- You may also want to change the hook message in /changeSecretWord/ to+-- properly log the reset case.+--+-- @+-- changeSecretWord :: ByteString -> IO L.ByteString+-- __/changeSecretWord/__ s = do+-- writeIORef secretWord s+-- return $ \"The secret word was \" \`L.append\` if B.null s+-- then \"reset\"+-- else \"changed\"+-- @ hookAdaptor :: ByteString -> NgxExportService hookAdaptor = ignitionService $
ngx-export-tools-extra.cabal view
@@ -1,5 +1,5 @@ name: ngx-export-tools-extra-version: 1.2.8+version: 1.2.8.1 synopsis: More extra tools for Nginx Haskell module description: More extra tools for <https://github.com/lyokha/nginx-haskell-module Nginx Haskell module>.@@ -40,7 +40,7 @@ , bytestring >= 0.10.0.0 , base64 >= 0.3.0.0 , ngx-export- , ngx-export-tools >= 1.2.2+ , ngx-export-tools >= 1.2.3.1 , http-types >= 0.7.0 , http-client >= 0.5.3 , http-client-tls >= 0.3.4