This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xavura's profile picture

Better HTTP configuration.

Started by Xavura, 08 March 2013 - 11:51 PM
Xavura #1
Posted 09 March 2013 - 12:51 AM
Reason for this request:

- Some servers want their users to be able to easily upload and download scripts but don't want them using HTTP for anything else. Or perhaps they only want them to use selected services (e.g. Web API X and Web API Y).

The solution to this problem is a http-host-whitelist in the config.

- Some servers may have silly users who have startup scripts that loop forever and fire off HTTP requests constantly, every second… (yes, that happened). It's a pain to moderate and educate all of your users to not be idiotic with HTTP.

The solution to this problem is a http-limit configuration option. When set to 10, this would mean each computer has to wait 10 seconds between sending HTTP requests.
Bubba #2
Posted 09 March 2013 - 05:10 AM
You can do this yourself. Edit the startup in the rom folder where it says "if http then …". Here's what I did just as a test:

if http then
    local oldRequest = http.request
    local lastRequestTime = 0
    local lastRequestDay = 0
    http.request = function(...)
        local cTime = math.floor(os.time()*100)
        local cDay = os.day()
        if cTime - lastRequestTime < 10 and lastRequestDay == cDay then
            return false, "Wait for "..10-(cTime-lastRequestTime).." seconds."
        else
            lastRequestTime = cTime
            lastRequestDay = cDay
            return oldRequest(...)
        end
    end
    sPath = sPath..":/rom/programs/http"
end
Cranium #3
Posted 09 March 2013 - 06:59 AM
I don't see this getting implemented, because as Bubba suggested, ths can be done with the tools already available to you. It just takes a little know-how to add it to your server.
ChunLing #4
Posted 09 March 2013 - 07:00 AM
Similarly, you can wrap the http API so that the get and post commands will error out if the site name isn't on a whitelist table in the API (kept local).