Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit 4a7439a

Browse files
committed
Merge branch 'dev' of https://github.com/hkalexling/Mango into dev
2 parents 00e1939 + 794bed1 commit 4a7439a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/plugin/plugin.cr

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,48 @@ class Plugin
257257
end
258258
sbx.put_prop_string -2, "get"
259259

260+
sbx.push_proc LibDUK::VARARGS do |ptr|
261+
env = Duktape::Sandbox.new ptr
262+
url = env.require_string 0
263+
body = env.require_string 1
264+
265+
headers = HTTP::Headers.new
266+
267+
if env.get_top == 3
268+
env.enum 2, LibDUK::Enum::OwnPropertiesOnly
269+
while env.next -1, true
270+
key = env.require_string -2
271+
val = env.require_string -1
272+
headers.add key, val
273+
env.pop_2
274+
end
275+
end
276+
277+
res = HTTP::Client.post url, headers, body
278+
279+
env.push_object
280+
281+
env.push_int res.status_code
282+
env.put_prop_string -2, "status_code"
283+
284+
env.push_string res.body
285+
env.put_prop_string -2, "body"
286+
287+
env.push_object
288+
res.headers.each do |k, v|
289+
if v.size == 1
290+
env.push_string v[0]
291+
else
292+
env.push_string v.join ","
293+
end
294+
env.put_prop_string -2, k
295+
end
296+
env.put_prop_string -2, "headers"
297+
298+
env.call_success
299+
end
300+
sbx.put_prop_string -2, "post"
301+
260302
sbx.push_proc 2 do |ptr|
261303
env = Duktape::Sandbox.new ptr
262304
html = env.require_string 0

0 commit comments

Comments
 (0)