Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow max HTTP response size to be configured in the manifest #18

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions manifest/Extism/Manifest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading