From 3b315ad880b3a45f269485a7a463cbac13d33cf4 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Fri, 24 Jul 2020 13:56:54 +0000 Subject: [PATCH] Pass status code and headers to plugin scripts --- src/plugin/plugin.cr | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugin/plugin.cr b/src/plugin/plugin.cr index 6f58619..850f129 100644 --- a/src/plugin/plugin.cr +++ b/src/plugin/plugin.cr @@ -238,9 +238,22 @@ class Plugin end res = HTTP::Client.get url, headers - body = res.body - env.push_string body + env.push_object + + env.push_int res.status_code + env.put_prop_string -2, "status_code" + + env.push_string res.body + env.put_prop_string -2, "body" + + env.push_object + res.headers.each do |k, v| + env.push_string v.to_s + env.put_prop_string -2, k + end + env.put_prop_string -2, "headers" + env.call_success end sbx.put_prop_string -2, "get"