Skip to content

Commit 91c1949

Browse files
author
zach
authored
feat: allow max HTTP response size to be set using the manifest (#19)
1 parent bffeb29 commit 91c1949

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/main/java/org/extism/sdk/manifest/MemoryOptions.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
* Configures memory for the Wasm runtime.
77
* Memory is described in units of pages (64KB) and represent contiguous chunks of addressable memory.
88
*
9-
* @param max Max number of pages.
9+
* @param maxPages Max number of pages.
10+
* @param httpMax Max number of bytes returned by HTTP requests using extism_http_request
1011
*/
1112
public class MemoryOptions {
12-
@SerializedName("max")
13-
private final Integer max;
13+
@SerializedName("max_pages")
14+
private final Integer maxPages;
1415

15-
public MemoryOptions(Integer max) {
16-
this.max = max;
16+
@SerializedName("max_http_response_bytes")
17+
private final Integer maxHttpResponseBytes;
18+
19+
public MemoryOptions(Integer maxPages, Integer httpMax) {
20+
this.maxPages = maxPages;
21+
this.maxHttpResponseBytes = httpMax;
1722
}
1823
}

src/test/java/org/extism/sdk/ManifestTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ public void shouldSerializeManifestWithWasmSourceToJson() {
3232
@Test
3333
public void shouldSerializeManifestWithWasmSourceAndMemoryOptionsToJson() {
3434

35-
var manifest = new Manifest(List.of(CODE.pathWasmSource()), new MemoryOptions(4));
35+
var manifest = new Manifest(List.of(CODE.pathWasmSource()), new MemoryOptions(4, 1024 * 1024 * 10));
3636
var json = JsonSerde.toJson(manifest);
3737
assertNotNull(json);
3838

3939
assertJson(json).at("/wasm").isArray();
4040
assertJson(json).at("/wasm").hasSize(1);
41-
assertJson(json).at("/memory/max").isEqualTo(4);
41+
assertJson(json).at("/memory/max_pages").isEqualTo(4);
42+
assertJson(json).at("/memory/max_http_response_bytes").isEqualTo(1024 * 1024 * 10);
4243
}
4344

4445
@Test

src/test/java/org/extism/sdk/PluginTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class PluginTests {
2121

2222
@Test
2323
public void shouldInvokeFunctionWithMemoryOptions() {
24-
var manifest = new Manifest(List.of(CODE.pathWasmSource()), new MemoryOptions(0));
24+
var manifest = new Manifest(List.of(CODE.pathWasmSource()), new MemoryOptions(0, 0));
2525
assertThrows(ExtismException.class, () -> {
2626
Extism.invokeFunction(manifest, "count_vowels", "Hello World");
2727
});

0 commit comments

Comments
 (0)