diff --git a/NgxExport/Tools/ServiceHookAdaptor.hs b/NgxExport/Tools/ServiceHookAdaptor.hs index 38a7658..d340f69 100644 --- a/NgxExport/Tools/ServiceHookAdaptor.hs +++ b/NgxExport/Tools/ServiceHookAdaptor.hs @@ -218,9 +218,8 @@ import Control.Monad -- 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/. +-- directive /rewrite/ to process the reset request in location /\/change_sw/. -- --- ==== File /nginx.conf/: reset the secret word by /rewrite/ -- @ -- location \/reset_sw { -- allow 127.0.0.1; @@ -230,7 +229,17 @@ import Control.Monad -- } -- @ -- --- You may also want to add a proper message for reset in /changeSecretWord/. +-- 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 $ diff --git a/README.md b/README.md index 468c9f1..61136e0 100644 --- a/README.md +++ b/README.md @@ -1867,9 +1867,7 @@ The order of their execution in a restarted worker process is not defined, 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*. - -###### File *nginx.conf*: reset the secret word by *rewrite* +directive *rewrite* to process the reset request in location */change_sw*. ```nginx location /reset_sw { @@ -1880,7 +1878,17 @@ directive *rewrite*. } ``` -You may also want to add a proper message for reset in *changeSecretWord*. +You may also want to change the hook message in *changeSecretWord* to +properly log the reset case. + +```haskell +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" +``` #### Module *NgxExport.Tools.Subrequest* diff --git a/test/ServiceHookAdaptor/test_tools_extra_servicehookadaptor.hs b/test/ServiceHookAdaptor/test_tools_extra_servicehookadaptor.hs index 7b856ba..d51160d 100644 --- a/test/ServiceHookAdaptor/test_tools_extra_servicehookadaptor.hs +++ b/test/ServiceHookAdaptor/test_tools_extra_servicehookadaptor.hs @@ -35,10 +35,8 @@ ngxExportIOYY 'testSecretWord changeSecretWord :: ByteString -> IO L.ByteString changeSecretWord s = do writeIORef secretWord s - return $ L.concat ["The secret word was " - ,if B.null s - then "reset" - else "changed" - ] + return $ "The secret word was " `L.append` if B.null s + then "reset" + else "changed" ngxExportServiceHook 'changeSecretWord