Jump to content

Internet

From Advanced Computers Wiki

The InternetUD component allows making real-world HTTP(s) requests. In order to be able to send HTTP(s) requests, make sure the current computer is connected to a WAN Router either directly via Network Cable or indirectly through Network Routers.

Security

By default, requests to local IP addresses are blocked (e.g. http://127.0.0.1). Domains are not filtered. You can allow access to local IPs by disabling the filtering in the config file.

Disabling this filtering will allow ingame computers to access webservices on the server's local machine or network. This could pose a security threat if any of those local webservices assume local traffic to be trustworthy. Be careful!

If you wish, HTTP(s) functionality can also be disabled entirely in the config file. This completely removes the ability to make any kind of HTTP(s) requests.

API

InternetUD component properties
Name Type Read/Write Description
isHttpEnabled bool READ Returns whether HTTP(s) is enabled at all. True by default, but can be changed in the server's config. Required to be true in order to use any methods.
isConnectedToWan bool READ Returns whether the current computer can reach a WAN router via the network. Required to be true in order to use any methods.
InternetUD component methods
Name Returns Description
:sendHttpRequest(url:string[, method:string[, postData:string[, headers:table]]]) HttpResponseUD Asynchronously sends an HTTP(s) request to the given URL with the given request method (e.g. GET, POST, etc.).

If the request method is set to something supporting a post body, you may provide one as a string in postData. Otherwise postData must be set to "". Headers may be provided as a table consisting of string keys and string values. The request method TRACE is not allowed for security reasons.

Handling responses

Upon making an HTTP(s) request you are provided with an HttpResponseUD object offering the following functionality.

HttpResponseUD properties
Name Type Read/Write Description
responseAvailable bool READ Returns whether this HTTP(s) request has been completed and therefore a response is available.
HttpResponseUD methods
Name Returns Description
:waitForCompletion() void Blocks until responseAvailable is true. All other functions implicitly call this prior to executing and thus show the same behaviour.
:getStatusCode() int Returns the HTTP status code of the response. Response codes in the 2xx range typically indicate success.
:getResponseBody() string Returns the response body as a string.
:getResponseBodySize() int Returns the length of the string that will be returned by :getResponseBody().
:getResponseHeaders() table Returns a table listing all response headers. Headers with multiple values are concatenated using commas as a delimeter.