Skip to content

Commit

Permalink
more improvements in the test example in PCRE module
Browse files Browse the repository at this point in the history
  • Loading branch information
lyokha committed Mar 10, 2024
1 parent 73fa149 commit 4d57691
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
15 changes: 12 additions & 3 deletions NgxExport/Tools/ServiceHookAdaptor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 $
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4d57691

Please sign in to comment.