From 7138947db1882d83b99afa6be6b0ef44bebb78f8 Mon Sep 17 00:00:00 2001 From: zach Date: Wed, 7 Feb 2024 14:21:32 -0800 Subject: [PATCH] feat: allow max HTTP request size to be configured in the manifest --- manifest/Extism/Manifest.hs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/manifest/Extism/Manifest.hs b/manifest/Extism/Manifest.hs index b789c6e..d3a5cb3 100644 --- a/manifest/Extism/Manifest.hs +++ b/manifest/Extism/Manifest.hs @@ -7,19 +7,23 @@ import Text.JSON import Text.JSON.Generic -- | Memory options -newtype Memory = Memory - { memoryMaxPages :: Nullable Int +data Memory = Memory + { memoryMaxPages :: Nullable Int, + memoryMaxHttpResponseBytes :: Nullable Int } deriving (Eq, Show) instance JSON Memory where - showJSON (Memory max) = + showJSON (Memory max maxHttp) = object - [ "max_pages" .= max + [ "max_pages" .= max, + "max_http_response_bytes" .= maxHttp ] readJSON obj = - let max = obj .? "max_pages" - in Ok (Memory max) + let + max = obj .? "max_pages" + httpMax = obj .? "max_http_response_bytes" + in Ok (Memory max httpMax) -- | HTTP request data HTTPRequest = HTTPRequest @@ -235,7 +239,21 @@ withTimeout m t = -- | Set memory.max_pages withMaxPages :: Manifest -> Int -> Manifest withMaxPages m pages = - m {memory = NotNull $ Memory (NotNull pages)} + case memory m of + Null -> + m {memory = NotNull $ Memory (NotNull pages) Null} + NotNull (Memory _ x) -> + m {memory = NotNull $ Memory (NotNull pages) x} + + +-- | Set memory.max_http_response_bytes +withMaxHttpResponseBytes :: Manifest -> Int -> Manifest +withMaxHttpResponseBytes m max = + case memory m of + Null -> + m {memory = NotNull $ Memory Null (NotNull max)} + NotNull (Memory x _) -> + m {memory = NotNull $ Memory x (NotNull max)} fromString :: String -> Either String Manifest fromString s = do