So I have a function that currently downloads .json files from a MUD's associated API. It's worked for years for me and looks like this
It seems like now, whenever I try to download the file using this function, I get the error:
1="HTTP/1.1 301 Moved Permanently"
2="Date: Tue, 18 Dec 2018 01:17:35 GMT"
3="Server: Apache/2.4.10 (Debian)"
4="Location: https://api.lusternia.com/characters/rivius.json"
5="Cache-Control: max-age=0"
6="Expires: Tue, 18 Dec 2018 01:17:35 GMT"
7="Content-Length: 339"
8="Connection: close"
9="Content-Type: text/html; charset=iso-8859-1"
10=""
11="<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">"
12="<html><head>"
13="<title>301 Moved Permanently</title>"
14="</head><body>"
15="<h1>Moved Permanently</h1>"
16="<p>The document has moved <a href="https://api.lusternia.com/characters/rivius.json">here</a>.</p>"
17="<hr>"
18="<address>Apache/2.4.10 (Debian) Server at api.lusternia.com Port 80</address>"
19="</body></html>"
I have poor knowledge of these things, but I suspect there was a silent change forcing https, which I'm guessing Luasocket doesn't support. Is there a relatively painless way of overcoming this to get the function working again?
function download_json(host, file)
local c = assert(socket.connect(host, 80))
c:send("GET "..file.." HTTP/1.1\r\nUser-agent: "..socket._VERSION.."\r\nHost: "..host.."\r\nConnection: close\r\n\r\n")
local js = {}
while true do
local s, stat, p = receive(c)
if not s and p then
if (#p > 0) then
s = p
end
end
js[#js + 1] = s
if (stat == "closed") then
break
end
end
c:close() -- close the connection
return string.match(table.concat(js, "\n"), "(%{.+%})")
end
It seems like now, whenever I try to download the file using this function, I get the error:
1="HTTP/1.1 301 Moved Permanently"
2="Date: Tue, 18 Dec 2018 01:17:35 GMT"
3="Server: Apache/2.4.10 (Debian)"
4="Location: https://api.lusternia.com/characters/rivius.json"
5="Cache-Control: max-age=0"
6="Expires: Tue, 18 Dec 2018 01:17:35 GMT"
7="Content-Length: 339"
8="Connection: close"
9="Content-Type: text/html; charset=iso-8859-1"
10=""
11="<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">"
12="<html><head>"
13="<title>301 Moved Permanently</title>"
14="</head><body>"
15="<h1>Moved Permanently</h1>"
16="<p>The document has moved <a href="https://api.lusternia.com/characters/rivius.json">here</a>.</p>"
17="<hr>"
18="<address>Apache/2.4.10 (Debian) Server at api.lusternia.com Port 80</address>"
19="</body></html>"
I have poor knowledge of these things, but I suspect there was a silent change forcing https, which I'm guessing Luasocket doesn't support. Is there a relatively painless way of overcoming this to get the function working again?