💾 Archived View for gemini.conman.org › extensions › GLV-1 › handlers › redirhell.lua captured on 2023-07-10 at 17:37:58.

View Raw

More Information

⬅️ Previous capture (2022-06-04)

-=-=-=-=-=-=-

-- ************************************************************************
--
--    Redirection Hell Torture Test
--    Copyright 2019 by Sean Conner.  All Rights Reserved.
--
--    This program is free software: you can redistribute it and/or modify
--    it under the terms of the GNU General Public License as published by
--    the Free Software Foundation, either version 3 of the License, or
--    (at your option) any later version.
--
--    This program is distributed in the hope that it will be useful,
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--    GNU General Public License for more details.
--
--    You should have received a copy of the GNU General Public License
--    along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
--    Comments, questions and criticisms can be sent to: sean@conman.org
--
-- ************************************************************************
-- luacheck: globals handler
-- luacheck: ignore 611

local uuid     = require "org.conman.uuid"
local uurl     = require "GLV-1.url-util"
local string   = require "string"
local math     = require "math"
local tostring = tostring

_ENV = {}

function handler(conf,auth,loc,pathinfo,ios)
  if pathinfo == "" then
    loc.path = loc.path .. "/"
    ios:write("31 ",uurl.toa(loc),"\r\n")
    return 31
  end
  
  if not pathinfo:match "^/" then
    loc.path = conf.path .. "/"
    ios:write("31 ",uurl.toa(loc),"\r\n")
    return 31
  end
  
  local path = { path = tostring(uuid(uuid.URL,auth._remote .. auth._port)) }
  
  if conf.redirect then
    ios:write(string.format("%d %s\r\n",conf.redirect,uurl.toa(uurl.merge(loc,path))))
    return conf.redirect
  else
    local status = math.random(30,31)
    ios:write(string.format("%d %s\r\n",status,uurl.toa(uurl.merge(loc,path))))
    return status
  end
end

return _ENV