0

I'm trying to retrieve pages from a web server via https, using lua with luasec. For most pages my script works as intended, but if the ressource contains special characters (like ,'é), I'm being sent into a loop with 301 responses.

let this code sniplet illustrate my dilemma (actual server details redacted to protect the innocent):

local https = require "ssl.https"
local prefix = "https://www.example.com"
local suffix = "/S%C3%A9ance"
local body,code,headers,status = https.request(prefix .. suffix)
print(status .. " - GET was for \"" .. prefix .. suffix .. "\"")
print("headers are " .. myTostring(headers))
print("body is " .. myTostring(body))
if suffix == headers.location then
    print("equal")
else
    print("not equal")
end
local body,code,headers,status = https.request(prefix .. headers.location)
print(status .. " - GET was for \"" .. prefix .. suffix .. "\"")

which results in the paradoxical

HTTP/1.1 301 Moved Permanently - GET was for "https://www.example.com/S%C3%A9ance" headers are { ["content-type"]="text/html; charset=UTF-8";["set-cookie"]="PHPSESSID=e80oo5dkouh8gh0ruit7mj28t6; path=/";["content-length"]="0";["connection"]="close";["date"]="Wed, 15 Mar 2017 19:31:24 GMT";["location"]="S%C3%A9ance";} body is "" equal HTTP/1.1 301 Moved Permanently - GET was for "https://www.example.com/S%C3%A9ance"

How might one be able to retrieve the elusive pages, using lua and as little additional dependencies as possible?

1 Answers1

0

Obvious as it may seem, perhaps the requested url does differ from the actual location.

If you have a similar problem, do check deep within your external libraries to make sure they do what you think they do.

In this case, luasocket did urldecode and then urlencode the url and thus the final request was not what it seemed to be.