This file is indexed.

/usr/share/lua/5.1/wsapi/response.lua is in lua-wsapi 1.6.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
local util = require "wsapi.util"

local date = os.date
local format = string.format

local _M = {}

local methods = {}
methods.__index = methods

_M.methods = methods

local unpack = table.unpack or unpack

function methods:write(...)
  for _, s in ipairs{ ... } do
    if type(s) == "table" then
      self:write(unpack(s))
    elseif s then
      local s = tostring(s)
      self.body[#self.body+1] = s
      self.length = self.length + #s
    end
  end
end

function methods:forward(url)
  self.env.PATH_INFO = url or self.env.PATH_INFO
  return "MK_FORWARD"
end

function methods:finish()
  self.headers["Content-Length"] = self.length
  return self.status, self.headers, coroutine.wrap(function ()
    for _, s in ipairs(self.body) do
     coroutine.yield(s)
    end
  end)
end

local function optional (what, name)
  if name ~= nil and name ~= "" then
    return format("; %s=%s", what, name)
  else
    return ""
  end
end

local function optional_flag(what, isset)
  if isset then
    return format("; %s", what)
  end
  return ""
end

local function make_cookie(name, value)
  local options = {}
  local t
  if type(value) == "table" then
    options = value
    value = value.value
  end
  local cookie = name .. "=" .. util.url_encode(value)
  if options.expires then
    t = date("!%A, %d-%b-%Y %H:%M:%S GMT", options.expires)
    cookie = cookie .. optional("expires", t)
  end
  if options.max_age then
    t = date("!%A, %d-%b-%Y %H:%M:%S GMT", options.max_age)
    cookie = cookie .. optional("Max-Age", t)
  end
  cookie = cookie .. optional("path", options.path)
  cookie = cookie .. optional("domain", options.domain)
  cookie = cookie .. optional_flag("secure", options.secure)
  cookie = cookie .. optional_flag("HttpOnly", options.httponly)
  return cookie
end

function methods:set_cookie(name, value)
  local cookie = self.headers["Set-Cookie"]
  if type(cookie) == "table" then
    table.insert(self.headers["Set-Cookie"], make_cookie(name, value))
  elseif type(cookie) == "string" then
    self.headers["Set-Cookie"] = { cookie, make_cookie(name, value) }
  else
    self.headers["Set-Cookie"] = make_cookie(name, value)
  end
end

function methods:delete_cookie(name, path, domain)
  self:set_cookie(name, { value =  "xxx", expires = 1, path = path, domain = domain })
end

function methods:redirect(url)
  self.status = 302
  self.headers["Location"] = url
  self.body = {}
  return self:finish()
end

function methods:content_type(type)
  self.headers["Content-Type"] = type
end

function _M.new(status, headers)
  status = status or 200
  headers = headers or {}
  if not headers["Content-Type"] then
    headers["Content-Type"] = "text/html"
  end
  return setmetatable({ status = status, headers = headers, body = {}, length = 0 }, methods)
end

return _M