mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
modify from http folder (#1470)
* delete unused var and add used arg * use interface from stream
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local socket = require "http.sockethelper"
|
local socket = require "http.sockethelper"
|
||||||
local url = require "http.url"
|
|
||||||
local internal = require "http.internal"
|
local internal = require "http.internal"
|
||||||
local dns = require "skynet.dns"
|
local dns = require "skynet.dns"
|
||||||
local string = string
|
local string = string
|
||||||
@@ -131,7 +130,7 @@ function httpc.head(hostname, url, recvheader, header, content)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function httpc.request_stream(method, hostname, url, header, content)
|
function httpc.request_stream(method, hostname, url, recvheader, header, content)
|
||||||
local fd, interface, host = connect(hostname, httpc.timeout)
|
local fd, interface, host = connect(hostname, httpc.timeout)
|
||||||
local ok , statuscode, body , header = pcall(internal.request, interface, method, host, url, recvheader, header, content)
|
local ok , statuscode, body , header = pcall(internal.request, interface, method, host, url, recvheader, header, content)
|
||||||
interface.finish = true -- don't shutdown fd in timeout
|
interface.finish = true -- don't shutdown fd in timeout
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
local internal = require "http.internal"
|
local internal = require "http.internal"
|
||||||
|
|
||||||
local table = table
|
|
||||||
local string = string
|
local string = string
|
||||||
local type = type
|
local type = type
|
||||||
|
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ local function stream_length(length)
|
|||||||
return function(stream)
|
return function(stream)
|
||||||
local body = stream._body
|
local body = stream._body
|
||||||
if body == nil then
|
if body == nil then
|
||||||
local ret, padding = interface.read()
|
local ret, padding = stream._interface.read()
|
||||||
if not ret then
|
if not ret then
|
||||||
-- disconnected
|
-- disconnected
|
||||||
body = padding
|
body = padding
|
||||||
@@ -353,7 +353,7 @@ function M.response_stream(interface, code, body, header)
|
|||||||
local read_func
|
local read_func
|
||||||
|
|
||||||
if mode == "chunked" then
|
if mode == "chunked" then
|
||||||
readfunc = stream_chunked
|
read_func = stream_chunked
|
||||||
else
|
else
|
||||||
-- identity mode
|
-- identity mode
|
||||||
local length = header["content-length"]
|
local length = header["content-length"]
|
||||||
@@ -361,11 +361,11 @@ function M.response_stream(interface, code, body, header)
|
|||||||
length = tonumber(length)
|
length = tonumber(length)
|
||||||
end
|
end
|
||||||
if length then
|
if length then
|
||||||
readfunc = stream_length(length)
|
read_func = stream_length(length)
|
||||||
elseif code == 204 or code == 304 or code < 200 then
|
elseif code == 204 or code == 304 or code < 200 then
|
||||||
readfunc = stream_nobody
|
read_func = stream_nobody
|
||||||
else
|
else
|
||||||
readfunc = stream_all
|
read_func = stream_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -375,7 +375,7 @@ function M.response_stream(interface, code, body, header)
|
|||||||
status = code,
|
status = code,
|
||||||
_body = body,
|
_body = body,
|
||||||
_interface = interface,
|
_interface = interface,
|
||||||
_reading = readfunc,
|
_reading = read_func,
|
||||||
header = header,
|
header = header,
|
||||||
connected = true,
|
connected = true,
|
||||||
}, stream)
|
}, stream)
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ function tlshelper.writefunc(fd, tls_ctx)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function tlshelper.readallfunc(fd, tls_ctx)
|
function tlshelper.readallfunc(fd, tls_ctx)
|
||||||
local readfunc = socket.readfunc(fd)
|
|
||||||
return function ()
|
return function ()
|
||||||
local ds = socket.readall(fd)
|
local ds = socket.readall(fd)
|
||||||
local s = tls_ctx:read(ds)
|
local s = tls_ctx:read(ds)
|
||||||
|
|||||||
Reference in New Issue
Block a user