HTTP handles

From ComputerCraft
Jump to navigation Jump to search
FunctionFunctionhandle.getResponseCode
Returns the numerical HTTP response code sent by the server.
Syntax handle.getResponseCode()
Returns number code string status
Part of CC:Tweaked (source)
API http
ExampleExampleGet response code
Gets the response code of "https://example.com" and print it.
Code
local response, err = http.get("https://example.com")
if not response then error(err, 0) end

print(response.getResponseCode())
Output 200
OK


FunctionFunctionhandle.getResponseHeaders
Returns a table containing the response’s headers, in a format similar to that required by http.request. If multiple headers are sent with the same name, they will be combined with a comma.
Syntax handle.getResponseHeaders()
Returns table headers
Part of CC:Tweaked (source)
API http
ExampleExampleGet response headers
Gets the response headers of "https://example.com" and print it.
Code
local response, err = http.get("https://example.com")
if not response then error(err, 0) end

local headers = response.getResponseHeaders()
print(headers["Content-Type"])
print(headers["Content-Length"])
Output text/html
1270