mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
httpd.write_response capture socket error
This commit is contained in:
@@ -227,8 +227,8 @@ local function readall(readbytes, bodylimit)
|
||||
return 200, url, method, header, body
|
||||
end
|
||||
|
||||
function httpd.read_request(readbytes, bodylimit)
|
||||
local ok, code, url, method, header, body = pcall(readall, readbytes, bodylimit)
|
||||
function httpd.read_request(...)
|
||||
local ok, code, url, method, header, body = pcall(readall, ...)
|
||||
if ok then
|
||||
return code, url, method, header, body
|
||||
else
|
||||
@@ -236,7 +236,7 @@ function httpd.read_request(readbytes, bodylimit)
|
||||
end
|
||||
end
|
||||
|
||||
function httpd.write_response(writefunc, statuscode, bodyfunc, header)
|
||||
local function writeall(writefunc, statuscode, bodyfunc, header)
|
||||
local statusline = string.format("HTTP/1.1 %03d %s\r\n", statuscode, http_status_msg[statuscode] or "")
|
||||
writefunc(statusline)
|
||||
if header then
|
||||
@@ -267,4 +267,8 @@ function httpd.write_response(writefunc, statuscode, bodyfunc, header)
|
||||
end
|
||||
end
|
||||
|
||||
function httpd.write_response(...)
|
||||
return pcall(writeall, ...)
|
||||
end
|
||||
|
||||
return httpd
|
||||
|
||||
@@ -4,7 +4,7 @@ local readbytes = socket.read
|
||||
local writebytes = socket.write
|
||||
|
||||
local sockethelper = {}
|
||||
local socket_error = {}
|
||||
local socket_error = setmetatable({} , { __tostring = function() return "[Socket Error]" end })
|
||||
|
||||
sockethelper.socket_error = socket_error
|
||||
|
||||
@@ -28,4 +28,4 @@ function sockethelper.writefunc(fd)
|
||||
end
|
||||
end
|
||||
|
||||
return sockethelper
|
||||
return sockethelper
|
||||
|
||||
Reference in New Issue
Block a user