sniper00 / moon

A lightweight game server framework implemented with Actor Model
MIT License
761 stars 169 forks source link

400 Bad Request: The plain HTTP request was sent to HTTPS port #171

Closed lonag closed 2 months ago

lonag commented 3 months ago

使用httpc.get访问https接口,看表现是会用http访问。

sniper00 commented 3 months ago

Moon不直接支持https, HTTPS需要用代理,可以看下wiki

https://github.com/sniper00/moon/wiki/Http#httpclient-http%E8%BD%AChttps%E6%AD%A3%E5%90%91%E4%BB%A3%E7%90%86%E9%85%8D%E7%BD%AE

示例

--httpsGoogle登录令牌认证
local function GoogleTokenVerify(token, userId)

    local url = string.format("https://oauth2.googleapis.com")
    local response = httpc.get(url, {
        path = string.format("/tokeninfo?id_token=%s", token),
        proxy = "http://127.0.0.1:8443"  -- 这里设置nginx http->https 正向代理
    })
    if response == nil or response.status_code ~= 200 or response.content == nil then 
        return 1
    end

    local jsonStr = json.decode(response.content)
    if jsonStr == nil then 
        return 2
    end

    if jsonStr["sub"] == nil or jsonStr["sub"] ~= userId then 
        return 3
    end

    return 0
end
lonag commented 3 months ago

好吧

sniper00 commented 3 months ago

好吧

主要原因是带上 OpenSSL 编译,会增加编译复杂度,使用nginx更加简洁高效, 并且线上环境一般都会依赖nginx。开发环境一般在内网部署一个,可以项目组共用。