2 return (status and 200 <= status and status < 300) or
false
6 return (status and 300 <= status and status < 400) or
false
10 local index, params = 1,
''
11 while param_list and param_dict and index <= #param_list
do
12 local
param = param_list[index]
13 local value = param_dict[
param]
19 params = params..
param..
'='..(value or
'')
33 self.add_body_content = function (
body)
34 self.body_content = self.body_content..(
body or
'')
38 self.add_imutable_header = function (
header, value, cond)
39 if cond ==
false then
return self end
40 if self.header_imutable[
header] == nil then
41 self.header_list[#self.header_list + 1] =
header
42 self.header_dict[
header] = value
43 elseif self.header_imutable[
header] ==
false then
44 self.header_dict[
header] = value
46 self.header_imutable[
header] =
true
50 self.add_mutable_header = function (
header, value, cond)
51 if cond ==
false then
return self end
52 if self.header_imutable[
header] == nil then
53 self.header_list[#self.header_list + 1] =
header
54 self.header_imutable[
header] =
false
55 self.header_dict[
header] = value
60 self.add_custom_headers = function(header_list, header_dict)
62 while header_list and #header_list >= index
do
63 local
header = header_list[index]
64 local value = header_dict[
header]
66 if self.header_imutable[
header] == nil then
67 self.header_list[#self.header_list + 1] =
header
68 self.header_imutable[
header] =
false
69 self.header_dict[
header] = value
70 elseif self.header_imutable[
header] ==
false then
71 self.header_dict[
header] = value
79 self.to_http_protocol = function ()
81 local request = method..' '..uri..' HTTP/1.1\r\n'
83 while index <=
#self.header_list do
84 local
header = self.header_list[index]
85 local value = self.header_dict[
header]
86 request = request..
header..
': '..value..
'\r\n'
90 request = request..
'\r\n'
92 if method ~=
'GET' and method ~=
'HEAD' and #self.body_content > 0 then
93 request = request..self.body_content..
'\r\n\r\n'
96 return request, function() end
99 self.to_curl_cmd = function ()
101 local request = 'curl -L -'..'-silent -'..'-insecure -w "\n%{http_code}
" '
103 if method == 'HEAD' then
104 request = request..'-'..'-HEAD '
106 request = request..'-X '..method..' '
109 while index <= #self.header_list do
110 local header = self.header_list[index]
111 local value = self.header_dict[header]
112 request = request..'-H "'..header..':
'..value..'" '
116 if method ~= 'GET' and method ~= 'HEAD' and #self.body_content > 0 then
117 request = request..'-d \''..self.body_content..'\' '
120 request = request..uri
123 return request, function() end
131 is_redirect=is_redirect,
132 url_search_param=url_search_param,
133 create_request=create_request
local function header(self, name, value)
local function body(self, content)
local function param(self, name, value)