Как сбросить кэш в асинхронном HTTP-запросе?

yoshishi

Новичок
Автор темы
14
0
Версия MoonLoader
.027.0-preview
How do I reset the cache in an asynchronous HTTP request?
 

sazzas1978

Известный
124
121
How do I reset the cache in an asynchronous HTTP request?
C++:
local copas = require 'copas'
local http = require 'copas.http'

-- Enhanced httpRequest function with cache-control headers
function httpRequest(request, body, handler)
    local function executeRequest(url, requestBody, responseHandler)
        local headers = {
            ["Cache-Control"] = "no-cache",  -- Prevent caching
            ["Pragma"] = "no-cache",         -- Legacy directive for HTTP/1.0
            ["Expires"] = "0"                -- Expired immediately
        }

        local options = {
            url = url,
            headers = headers,
            method = "GET"  -- Use "GET" or "POST" based on request type
        }

        local response, status, headers = http.request(options)

        -- Handle the response using the provided handler function
        if responseHandler then
            responseHandler(response, status, headers)
        end
    end
    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)
            executeRequest(r, b, h)
        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(executeRequest(r, b))
        end, request, body)
        while coroutine.status(thread) ~= 'dead' do wait(0) end
        return table.unpack(results)
    end
end
There are two ways:
1)Add Cache headers like in my example;
2)Add some random params in request to prevent caching