Skip to content

Commit 999eb3b

Browse files
committed
feat: add allow_http_response_headers to Plugin->new to allow plugins to access http response headers
1 parent 4f98e96 commit 999eb3b

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

Extism/lib/Extism/Plugin.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use Carp qw(croak);
77
use Extism::XS qw(
88
plugin_new
99
plugin_new_with_fuel_limit
10+
plugin_allow_http_response_headers
1011
plugin_new_error_free
1112
plugin_call
1213
plugin_error
@@ -33,6 +34,7 @@ sub new {
3334
my $functions = [];
3435
my $with_wasi = 0;
3536
my $fuel_limit;
37+
my $allow_http_response_headers;
3638
if ($options) {
3739
if (exists $options->{functions}) {
3840
$functions = $options->{functions};
@@ -43,6 +45,9 @@ sub new {
4345
if (exists $options->{fuel_limit}) {
4446
$fuel_limit = $options->{fuel_limit};
4547
}
48+
if (exists $options->{allow_http_response_headers}) {
49+
$allow_http_response_headers = $options->{allow_http_response_headers};
50+
}
4651
}
4752
my $errptr = "\x00" x 8;
4853
my $errptrptr = unpack('Q', pack('P', $errptr));
@@ -57,6 +62,9 @@ sub new {
5762
plugin_new_error_free(unpack('Q', $errptr));
5863
croak $errmsg;
5964
}
65+
if ($allow_http_response_headers) {
66+
plugin_allow_http_response_headers($plugin);
67+
}
6068
bless \$plugin, $name
6169
}
6270

Extism/lib/Extism/XS.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ our @EXPORT_OK = qw(
1515
version
1616
plugin_new
1717
plugin_new_with_fuel_limit
18+
plugin_allow_http_response_headers
1819
plugin_new_error_free
1920
plugin_call
2021
plugin_error

Extism/lib/Extism/XS.xs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ plugin_new_with_fuel_limit(wasm, wasm_size, functions, n_functions, with_wasi, f
118118
RETVAL
119119

120120
void
121-
plugin_new_error_free(err);
121+
plugin_allow_http_response_headers(plugin)
122+
ExtismPlugin *plugin
123+
CODE:
124+
extism_plugin_allow_http_response_headers(plugin);
125+
126+
void
127+
plugin_new_error_free(err)
122128
void *err
123129
CODE:
124130
extism_plugin_new_error_free(err);

Extism/t/02-extism.t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use Extism ':all';
77
use JSON::PP qw(encode_json decode_json);
88
use File::Temp qw(tempfile);
99
use Devel::Peek qw(Dump);
10-
plan tests => 50;
10+
plan tests => 51;
1111

1212
# ...
1313
ok(Extism::version());
@@ -255,3 +255,9 @@ ok($@->{message});
255255
};
256256
ok($@);
257257
}
258+
259+
# http headers
260+
{
261+
my $plugin = Extism::Plugin->new($wasm, {wasi => 1, allow_http_response_headers => 1});
262+
ok($plugin);
263+
}

0 commit comments

Comments
 (0)