body not sending, needs fix

This commit is contained in:
Thomas Lynch
2021-12-30 17:43:30 +11:00
parent 2fbba3c8f8
commit c2be84c4f8

View File

@ -1,7 +1,6 @@
_M = {} _M = {}
local url = require("url") local url = require("url")
local http = require("http")
local utils = require("utils") local utils = require("utils")
local cookie = require("cookie") local cookie = require("cookie")
local json = require("json") local json = require("json")
@ -141,16 +140,28 @@ function _M.view(applet)
elseif applet.method == "POST" then elseif applet.method == "POST" then
local parsed_body = url.parseQuery(applet.receive(applet)) local parsed_body = url.parseQuery(applet.receive(applet))
if parsed_body["h-captcha-response"] then if parsed_body["h-captcha-response"] then
local url = string.format( local hcaptcha_url = string.format(
"https://%s/siteverify?secret=%s&response=%s", "https://%s/siteverify",
core.backends["hcaptcha"].servers["hcaptcha"]:get_addr(), core.backends["hcaptcha"].servers["hcaptcha"]:get_addr()
captcha_secret, )
parsed_body["h-captcha-response"] local hcaptcha_body = json.encode({
) secret=captcha_secret,
local res, err = http.get{url=url, headers={host=captcha_provider_domain} } response=parsed_body["h-captcha-response"]
local status, api_response = pcall(res.json, res) })
local httpclient = core.httpclient()
local res = httpclient:post{
url=hcaptcha_url,
body=hcaptcha_body,
headers={
[ "host" ] = { captcha_provider_domain },
[ "content-type" ] = { "application/json" }
}
}
local status, api_response = pcall(json.decode, res.body)
--require("print_r")
--print_r(res)
--print_r(api_response)
if not status then if not status then
local original_error = api_response
api_response = {} api_response = {}
end end
if api_response.success == true then if api_response.success == true then