Skip to content

Commit

Permalink
feat: add allow_http_response_headers to Plugin->new to allow plugins…
Browse files Browse the repository at this point in the history
… to access http response headers
  • Loading branch information
G4Vi committed Nov 26, 2024
1 parent 4f98e96 commit 999eb3b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Extism/lib/Extism/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Carp qw(croak);
use Extism::XS qw(
plugin_new
plugin_new_with_fuel_limit
plugin_allow_http_response_headers
plugin_new_error_free
plugin_call
plugin_error
Expand All @@ -33,6 +34,7 @@ sub new {
my $functions = [];
my $with_wasi = 0;
my $fuel_limit;
my $allow_http_response_headers;
if ($options) {
if (exists $options->{functions}) {
$functions = $options->{functions};
Expand All @@ -43,6 +45,9 @@ sub new {
if (exists $options->{fuel_limit}) {
$fuel_limit = $options->{fuel_limit};
}
if (exists $options->{allow_http_response_headers}) {
$allow_http_response_headers = $options->{allow_http_response_headers};
}
}
my $errptr = "\x00" x 8;
my $errptrptr = unpack('Q', pack('P', $errptr));
Expand All @@ -57,6 +62,9 @@ sub new {
plugin_new_error_free(unpack('Q', $errptr));
croak $errmsg;
}
if ($allow_http_response_headers) {
plugin_allow_http_response_headers($plugin);
}
bless \$plugin, $name
}

Expand Down
1 change: 1 addition & 0 deletions Extism/lib/Extism/XS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ our @EXPORT_OK = qw(
version
plugin_new
plugin_new_with_fuel_limit
plugin_allow_http_response_headers
plugin_new_error_free
plugin_call
plugin_error
Expand Down
8 changes: 7 additions & 1 deletion Extism/lib/Extism/XS.xs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ plugin_new_with_fuel_limit(wasm, wasm_size, functions, n_functions, with_wasi, f
RETVAL

void
plugin_new_error_free(err);
plugin_allow_http_response_headers(plugin)
ExtismPlugin *plugin
CODE:
extism_plugin_allow_http_response_headers(plugin);

void
plugin_new_error_free(err)
void *err
CODE:
extism_plugin_new_error_free(err);
Expand Down
8 changes: 7 additions & 1 deletion Extism/t/02-extism.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Extism ':all';
use JSON::PP qw(encode_json decode_json);
use File::Temp qw(tempfile);
use Devel::Peek qw(Dump);
plan tests => 50;
plan tests => 51;

# ...
ok(Extism::version());
Expand Down Expand Up @@ -255,3 +255,9 @@ ok($@->{message});
};
ok($@);
}

# http headers
{
my $plugin = Extism::Plugin->new($wasm, {wasi => 1, allow_http_response_headers => 1});
ok($plugin);
}

0 comments on commit 999eb3b

Please sign in to comment.