Engine 0.0.4
Game engine in lua
Loading...
Searching...
No Matches
http_curl.lua
Go to the documentation of this file.
1local http_util = require('src/lib/util/http')
2
3local function http_handler(self)
4 local params = http_util.url_search_param(self.param_list, self.param_dict)
5 local command, cleanup = http_util.create_request(self.method, self.url..params)
6 .add_custom_headers(self.header_list, self.header_dict)
7 .add_body_content(self.body_content)
8 .to_curl_cmd()
9
10 local handle = io and io.popen and io.popen(command)
11
12 if handle then
13 local stdout = handle:read("*a")
14 local ok, stderr = handle:close()
15 local index = stdout:find("[^\n]*$") or 1
16 local status = tonumber(stdout:sub(index))
17 if not ok then
18 self.std.http.ok = false
19 self.std.http.error = stderr or stdout or 'unknown error!'
20 else
21 self.std.http.ok = 200 <= status and status < 300
22 self.std.http.body = stdout:sub(1, index - 2)
23 self.std.http.status = status
24 end
25 else
26 self.std.http.ok = false
27 self.std.http.error = 'failed to spawn process!'
28 end
29
30 cleanup()
31end
32
33local P = {
34 handler = http_handler
35}
36
37return P
local function stdout(self, format)
local function http_handler(self)
local http_util
Definition http_curl.lua:1
local function require(std, game, application)
local function body(self, content)
local function error(self, handler_func)
local function failed(self, handler_func)
local std
Definition main.lua:18
local function http(std, game)
create_request
Definition http.lua:29
url_search_param
Definition http.lua:28