Files
module-fastwebcore/target/fastweb/request.lua
2026-03-31 16:00:38 +08:00

160 lines
2.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
local session = require("fastweb.session")
local M = {}
--[[
FUNCTION 取协议头
PARAM
name : 名称
--]]
function M.header(name)
return fw_request:header(name)
end
--[[
FUNCTION 取协议头(表)
PARAM
name : 名称
--]]
function M.headers()
return fw_request:headers()
end
--[[
FUNCTION 取请求类型
RETURN
请求类型GET, POST, PUT, DEL, HEAD 等
--]]
function M.method()
return fw_request:method()
end
--[[
FUNCTION 取请求路径
--]]
function M.filepath()
return fw_request:filepath()
end
--[[
FUNCTION 取请求主机
--]]
function M.host()
return fw_request:host()
end
--[[
FUNCTION 取请求参数
DESC支持BODY、URL和JSON一级属性的获取。
PARAM
name 参数名
throw 为空时是否抛出异常
--]]
function M.param(name,throw)
return fw_request:param(name,throw)
end
--[[
FUNCTION 取请求发起IP地址
--]]
function M.remote_ipaddress()
return fw_request:remote_ipaddress()
end
--[[
FUNCTION 取请求发起端口
--]]
function M.remote_port()
return fw_request:remote_port()
end
--[[
FUNCTION 取会话session
PARAM
session_id 此ID自行维护唯一
--]]
function M.session(session_id)
return session.new(fw_request:session(session_id))
end
--[[
FUNCTION 获取请求体参数表
--]]
function M.body_param()
return fw_request:body_param()
end
--[[
FUNCTION 获取URL参数表
--]]
function M.url_param()
return fw_request:url_param()
end
--[[
FUNCTION 获取请求体字符串
--]]
function M.body()
return fw_request:body()
end
--[[
FUNCTION 获取表单信息
--]]
function M.multipart()
return fw_request:multipart()
end
--[[
FUNCTION 读取表单数据
--]]
function M.multipart_content(id)
return fw_request:multipart_content(id)
end
--[[
FUNCTION 保存表单数据
--]]
function M.multipart_content_save(id,filepath)
return fw_request:multipart_content_save(id,filepath)
end
--[[
FUNCTION 读取表单数据
--]]
function M.multipart_content_name(name)
-- 按name字段查找对应的表单条目取其id然后调用multipart_content
local multipart_list = M.multipart()
for _, item in ipairs(multipart_list or {}) do
if item.param and item.param.name == name then
return M.multipart_content(item.id)
end
end
return nil
end
--[[
FUNCTION 置临时数据(仅本次请求有效)
--]]
function M.set(name,value)
fw_request:set(name,value)
end
--[[
FUNCTION 取临时数据(仅本次请求有效)
--]]
function M.get(name)
return fw_request:get(name)
end
--[[
FUNCTION 取临时数据(仅本次请求有效)
--]]
function M.gets()
return fw_request:gets()
end
--[[
FUNCTION 保存请求体到文件
--]]
function M.save_body(filepath)
return fw_request:save_body(filepath)
end
return M