add https client and server support by bios

This commit is contained in:
zixun
2019-03-14 10:36:02 +08:00
parent 1422cae7fb
commit 7746193b5f
6 changed files with 634 additions and 20 deletions

View File

@@ -2,12 +2,15 @@ local skynet = require "skynet"
local httpc = require "http.httpc"
local dns = require "skynet.dns"
local function main()
local function http_test(protocol)
--httpc.dns() -- set dns server
httpc.timeout = 100 -- set timeout 1 second
print("GET baidu.com")
protocol = protocol or "http"
local respheader = {}
local status, body = httpc.get("baidu.com", "/", respheader)
local host = string.format("%s://baidu.com", protocol)
print("geting... ".. host)
local status, body = httpc.get(host, "/", respheader)
print("[header] =====>")
for k,v in pairs(respheader) do
print(k,v)
@@ -16,13 +19,20 @@ local function main()
print(body)
local respheader = {}
dns.server()
local ip = dns.resolve "baidu.com"
print(string.format("GET %s (baidu.com)", ip))
local status, body = httpc.get("baidu.com", "/", respheader, { host = "baidu.com" })
local status, body = httpc.get(host, "/", respheader, { host = "baidu.com" })
print(status)
end
local function main()
dns.server()
http_test("http")
print("---------")
http_test("https")
end
skynet.start(function()
print(pcall(main))
skynet.exit()