Skip to content

Commit

Permalink
cleanup: fix http_headers callback function and response when headers…
Browse files Browse the repository at this point in the history
… aren't enabled
  • Loading branch information
zshipko committed Oct 10, 2024
1 parent 0b83bfe commit 52c7ad1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion host.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) (
hostFunc("var_set", varSet)
hostFunc("http_request", httpRequest)
hostFunc("http_status_code", httpStatusCode)
hostFunc("http_headers", httpStatusCode)
hostFunc("http_headers", httpHeaders)
hostFunc("get_log_level", getLogLevel)

logFunc := func(name string, level LogLevel) {
Expand Down Expand Up @@ -597,6 +597,10 @@ func httpStatusCode(ctx context.Context, m api.Module) int32 {

func httpHeaders(ctx context.Context, _ api.Module) uint64 {
if plugin, ok := ctx.Value(PluginCtxKey("plugin")).(*Plugin); ok {
if plugin.LastResponseHeaders == nil {
return 0
}

data, err := json.Marshal(plugin.LastResponseHeaders)
if err != nil {
panic(err)
Expand Down

0 comments on commit 52c7ad1

Please sign in to comment.