GithubHelp home page GithubHelp logo

Comments (4)

kodai2199 avatar kodai2199 commented on June 16, 2024

For now I was able to circumvent the problem with a pretty ugly solution. I parse the response in a protected call, and if I get an error, I use string.match() to find the error code within the error message. Unfortunately the error message changes for codes 404 and 410, leaving no information on which of those two error codes was received. Since 404 is way more frequent, I decided to return 404 in that situation.

Of course a fix would be better.

function requestWithResponseCode(url, post_data, headers, method)
    local handle = internet.request(url, post_data, headers, method)
    local result = ""
    local success, error = pcall(function() for chunk in handle do result = result..chunk end end)
    if success == false and error ~= nil then
        local error_code = error:match("code: (%d%d%d) ")
        if error_code ~= nil then
            return error_code, result
        else
            return 404, result
        end
    end

   if success == true then
       local mt = getmetatable(handle)
       local code, message, headers = mt.__index.response()
       return code, result
   end
end

from opencomputers.

asiekierka avatar asiekierka commented on June 16, 2024

It was fixed, but then it was reverted as not every Minecraft configuration actually had the Apache HTTP client library, nor could I figure out in the limited maintenance time I have for the mod: 555ae0e

from opencomputers.

asiekierka avatar asiekierka commented on June 16, 2024

The problem, I suppose, is that:

  • a bunch of programs (like wget) depend on the old behaviour to some extent (they don't check the response code at all, assuming exception = failure),
  • reading the response code requires a relatively unintuitive while not response.finishConnect() do os.sleep(0.05) end ; local code, message = response.response() call, and should probably get a friendlier API.

So this would best go into an OpenComputers 1.9.0 update; but given the mod is essentially unmaintained...

from opencomputers.

asiekierka avatar asiekierka commented on June 16, 2024

@kodai2199 Hopefully this workaround will be to your satisfaction, for the time being.

from opencomputers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.