request.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. local session = require("fastweb.session")
  2. local M = {}
  3. --[[
  4. FUNCTION: 取协议头
  5. PARAM
  6. name : 名称
  7. --]]
  8. function M.header(name)
  9. return fw_request:header(name)
  10. end
  11. --[[
  12. FUNCTION: 取协议头(表)
  13. PARAM
  14. name : 名称
  15. --]]
  16. function M.headers()
  17. return fw_request:headers()
  18. end
  19. --[[
  20. FUNCTION: 取请求类型
  21. RETURN
  22. 请求类型:GET, POST, PUT, DEL, HEAD 等
  23. --]]
  24. function M.method()
  25. return fw_request:method()
  26. end
  27. --[[
  28. FUNCTION: 取请求路径
  29. --]]
  30. function M.filepath()
  31. return fw_request:filepath()
  32. end
  33. --[[
  34. FUNCTION: 取请求主机
  35. --]]
  36. function M.host()
  37. return fw_request:host()
  38. end
  39. --[[
  40. FUNCTION: 取请求参数
  41. DESC:支持BODY、URL和JSON一级属性的获取。
  42. PARAM
  43. name : 参数名
  44. throw : 为空时是否抛出异常
  45. --]]
  46. function M.param(name,throw)
  47. return fw_request:param(name,throw)
  48. end
  49. --[[
  50. FUNCTION: 取请求发起IP地址
  51. --]]
  52. function M.remote_ipaddress()
  53. return fw_request:remote_ipaddress()
  54. end
  55. --[[
  56. FUNCTION: 取请求发起端口
  57. --]]
  58. function M.remote_port()
  59. return fw_request:remote_port()
  60. end
  61. --[[
  62. FUNCTION: 取会话session
  63. PARAM
  64. session_id : 此ID自行维护唯一
  65. --]]
  66. function M.session(session_id)
  67. return session.new(fw_request:session(session_id))
  68. end
  69. --[[
  70. FUNCTION: 获取请求体参数表
  71. --]]
  72. function M.body_param()
  73. return fw_request:body_param()
  74. end
  75. --[[
  76. FUNCTION: 获取URL参数表
  77. --]]
  78. function M.url_param()
  79. return fw_request:url_param()
  80. end
  81. --[[
  82. FUNCTION: 获取请求体字符串
  83. --]]
  84. function M.body()
  85. return fw_request:body()
  86. end
  87. --[[
  88. FUNCTION: 获取表单信息
  89. --]]
  90. function M.multipart()
  91. return fw_request:multipart()
  92. end
  93. --[[
  94. FUNCTION: 读取表单数据
  95. --]]
  96. function M.multipart_content(id)
  97. return fw_request:multipart_content(id)
  98. end
  99. --[[
  100. FUNCTION: 保存表单数据
  101. --]]
  102. function M.multipart_content_save(id,filepath)
  103. return fw_request:multipart_content_save(id,filepath)
  104. end
  105. --[[
  106. FUNCTION: 读取表单数据
  107. --]]
  108. function M.multipart_content_name(name)
  109. -- 按name字段查找对应的表单条目,取其id,然后调用multipart_content
  110. local multipart_list = M.multipart()
  111. for _, item in ipairs(multipart_list or {}) do
  112. if item.param and item.param.name == name then
  113. return M.multipart_content(item.id)
  114. end
  115. end
  116. return nil
  117. end
  118. --[[
  119. FUNCTION: 置临时数据(仅本次请求有效)
  120. --]]
  121. function M.set(name,value)
  122. fw_request:set(name,value)
  123. end
  124. --[[
  125. FUNCTION: 取临时数据(仅本次请求有效)
  126. --]]
  127. function M.get(name)
  128. return fw_request:get(name)
  129. end
  130. --[[
  131. FUNCTION: 取临时数据(仅本次请求有效)
  132. --]]
  133. function M.gets()
  134. return fw_request:gets()
  135. end
  136. --[[
  137. FUNCTION: 保存请求体到文件
  138. --]]
  139. function M.save_body(filepath)
  140. return fw_request:save_body(filepath)
  141. end
  142. return M