POST запрос + Copas HTTP

invilso.

Известный
Автор темы
249
89
Версия MoonLoader
.027.0-preview
Привет. Мне нужно передать headers в асинхронном http запросе, но у меня это не получается.

Использую:
http req:
local copas = require 'copas'
local http = require 'copas.http'

httpRequest(
    link,
    payload, --Вот тут кароче надо передать headers в котором есть Autorization.
    function (response, code, headers, status)
        if code == 200 then
        sampAddChatMessage('Данные успешно получены.', -1)
    else
        sampAddChatMessage('При получении возникла ошибка.', -1)
        print('{FFFFFF}REQUEST ERROR: '..code)
    end
    end
)

function httpRequest(request, body, handler) -- copas.http
    if not copas.running then
        copas.running = true
        lua_thread.create(function()
            wait(0)
            while not copas.finished() do
                local ok, err = copas.step(0)
                if ok == nil then error(err) end
                wait(0)
            end
            copas.running = false
        end)
    end
    if handler then
        return copas.addthread(function(r, b, h)
            copas.setErrorHandler(function(err) h(nil, err) end)
            h(http.request(r, b))
        end, request, body, handler)
    else
        local results
        local thread = copas.addthread(function(r, b)
            copas.setErrorHandler(function(err) results = {nil, err} end)
            results = table.pack(http.request(r, b))
        end, request, body)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end
end

Я даже знаю почему не получается, в copas http уже зашиты собственные данные.
Почему?! (source copas http):
_M.parseRequest = function(u, b)
    local reqt = {
        url = u,
        target = {},
    }
    reqt.sink = ltn12.sink.table(reqt.target)
    if b then
        reqt.source = ltn12.source.string(b)
        reqt.headers = {
            ["content-length"] = string.len(b),
            ["content-type"] = "application/x-www-form-urlencoded"
        }
        reqt.method = "POST"
    end
    return reqt
end

_M.request = socket.protect(function(reqt, body)
    if base.type(reqt) == "string" then
        reqt = _M.parseRequest(reqt, body)
        local ok, code, headers, status = _M.request(reqt)

        if ok then
            return table.concat(reqt.target), code, headers, status
        else
            return nil, code
        end
    else
        reqt.create = reqt.create or tcp(reqt)
        return trequest(reqt)
    end
end)

Есть какое-то асинхронное решение которое может передать headers? или надо переписывать библиотеку?